Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. L = 100
  5. X0 = np.array([L,0])
  6. t = 48*60*60
  7. h = 1
  8. h_list = np.linspace(10,3600,num = 10)
  9. n = t*h
  10.  
  11. def euler(X0,h,t):
  12. x0 = X0[0]
  13. y0 = X0[1]
  14. T = 24*60*60
  15. w_list_x = np.zeros(t*h)
  16. w_list_y = np.zeros(t*h)
  17. w_list_x[0] = x0
  18. w_list_y[0] = y0
  19. for i in range(1,n):
  20. R = np.sqrt(w_list_x[i-1]**2+w_list_y[i-1]**2)
  21. w_list_x[i] = w_list_x[i-1] + h*(2*np.pi*R/T)*(-w_list_y[i-1]/R)
  22. w_list_y[i] = w_list_y[i-1] + h*(2*np.pi*R/T)*(w_list_x[i-1]/R)
  23.  
  24. return w_list_x,w_list_y
  25.  
  26. '''def analyticEndPosition(t_end):
  27. T = 24*60*60
  28. x_end = L/(1+(4*(np.pi**2)*(t**2))/T)
  29. y_end = (2*np.pi*t/T)*x_end
  30. return x_end, y_end'''
  31.  
  32. def calcError(h):
  33. wx,wy= euler(X0,h,t)
  34. errorSquared = np.abs(wx[0]-wx[t*h-1])**2+np.abs(wy[0]-wy[t*h-1])**2
  35. return np.sqrt(errorSquared)
  36.  
  37. wx,wy= euler(X0,h,t)
  38.  
  39. print(wx)
  40. print(wy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement