Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import numpy as np
  2. import random
  3.  
  4. def equation(phi_k, z, k, x):
  5.     while k == 1:
  6.         k = random.uniform(0,1)
  7.     u2 = k/(1-k)
  8.     phi = phi_k*np.pi
  9.     u = u2**0.5
  10.  
  11.     fc = z*(1+2*((1-z)/z)**0.5*u*np.cos(phi)+(u2*(1-z))/z)**(1-x/2)+(1-z)*(1-2*(z/(1-z))**0.5*u*np.cos(phi)+z/(1-z)*u2)**(1-x/2)
  12.     Hq = 1-(z*(1-z)/(1+u2))*(2*np.cos(phi)+((1-2*z)*u)/(z*(1-z))**0.5)**2
  13.  
  14.     return 1/(u2*(1+u2))*1/2*1/(2*np.pi)*Hq*np.log(fc)
  15.  
  16. def monteCarlo(equation, x, N):
  17.     I = 0
  18.    
  19.     for i in range(N):
  20.         phi_k = random.uniform(0,1)
  21.         z = random.uniform(0,1)
  22.         k = random.uniform(0,1)
  23.         I += equation(phi_k, z, k, x)
  24.  
  25.     return I/N
  26.  
  27. print(monteCarlo(equation, 0, 10000))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement