Exemplo n.º 1
0
#!/usr/bin/env python
import numpy as np
import histogram
import integrator as intr
import matplotlib as plt

N =100000
A = np.zeros(N)
b = 5
n = 1000
for i in range(N):
  A[i] = intr.exponential(b)
histogram.hist(A,n)

#problem 2
[w,Sw] = intr.monte_carlo_3d(intr.density,[-.5,-.5,-1],[1,1,1],intr.sphere,100000)
[x,Sw] = intr.monte_carlo_3d(intr.xmoment,[-.5,-.5,-1],[1,1,1],intr.sphere,100000)
[y,Sw] = intr.monte_carlo_3d(intr.ymoment,[-.5,-.5,-1],[1,1,1],intr.sphere,100000)
[z,Sw] = intr.monte_carlo_3d(intr.zmoment,[-.5,-.5,-1],[1,1,1],intr.sphere,100000)

print(x/w,y/w,z/w)
Exemplo n.º 2
0
                    H[2 * i + 1] = H[2 * i + 1] + 1
        else:
            for j in range(L):
                if A[j] > mi and A[j] <= mx:
                    H[2 * i] = H[2 * i] + 1
                    H[2 * i + 1] = H[2 * i + 1] + 1
        H[2 * i] = H[2 * i] / L
        H[2 * i + 1] = H[2 * i + 1] / L
    plt.plot(X, H)
    plt.ylim(0, 1)
    plt.show()


A = np.zeros(100000)
for m in range(100000):
    A[m] = intr.exponential(2)

hist(A, 100)

#The histogram looks very similar to the expected probability density function.

[w, Sw] = intr.monte_carlo_3d(intr.density, [-0.5, -0.5, -1], [1, 1, 1],
                              intr.sphere, 100000)
[x, Sx] = intr.monte_carlo_3d(intr.xmoment, [-0.5, -0.5, -1], [1, 1, 1],
                              intr.sphere, 100000)
[y, Sy] = intr.monte_carlo_3d(intr.ymoment, [-0.5, -0.5, -1], [1, 1, 1],
                              intr.sphere, 100000)
[z, Sz] = intr.monte_carlo_3d(intr.zmoment, [-0.5, -0.5, -1], [1, 1, 1],
                              intr.sphere, 100000)

print(x / w, y / w, z / w)
Exemplo n.º 3
0
      for k in range(L):
        if A[k] >= mi and A[k] <= mx:
          H[2*i] = H[2*i] + 1
          H[2*i+1] = H[2*i+1] + 1
    else:
      for j in range(L):
        if A[j] > mi and A[j] <= mx:
          H[2*i] = H[2*i] + 1
          H[2*i+1] = H[2*i+1] + 1
    H[2*i] = H[2*i] / L
    H[2*i+1] = H[2*i+1] / L
  plt.plot(X,H)
  plt.ylim(0,1)
  plt.show()

A = np.zeros(100000)
for m in range(100000):
  A[m] = intr.exponential(2)

hist(A,100)

#The histogram looks very similar to the expected probability density function.

[w,Sw] = intr.monte_carlo_3d(intr.density,[-0.5,-0.5,-1],[1,1,1],intr.sphere,100000)
[x,Sx] = intr.monte_carlo_3d(intr.xmoment,[-0.5,-0.5,-1],[1,1,1],intr.sphere,100000)
[y,Sy] = intr.monte_carlo_3d(intr.ymoment,[-0.5,-0.5,-1],[1,1,1],intr.sphere,100000)
[z,Sz] = intr.monte_carlo_3d(intr.zmoment,[-0.5,-0.5,-1],[1,1,1],intr.sphere,100000)

print(x/w,y/w,z/w)