Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. tbegin = 0 #Time beginst at
  2. tend = 1 #Time stops at
  3. t = tend - tbegin
  4. N = 10000 #Numbert of steps
  5.  
  6. dt = float(t)/N
  7. t_arr = np.linspace(0, 1, N) #All the time steps
  8. y = np.zeros(N)
  9. y[0] = 0.3 #Starting point
  10.  
  11. if(len(t_arr) == N): #Just to check that these are equal
  12.     print "OK"
  13.  
  14. W = np.zeros(N)
  15.  
  16. for i in range(0, N - 1): #Get the steps for the Wiender process so that we can calculate dW = W[t+1] - W[t]
  17.     W[i+1] = W[i] + np.sqrt(dt) * np.random.normal(0, 1)
  18.  
  19. for i in range(1, N):
  20.     y[i] = y[i-1] + v * y[i-1] * dt + np.sqrt(2 * D * y[i-1]) * (W[i] - W[i-1])
  21.    
  22.  
  23. plt.plot(t_arr, y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement