Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- L = 100
- X0 = np.array([L,0])
- t = 48*60*60
- h = 1
- h_list = np.linspace(10,3600,num = 10)
- n = t*h
- def euler(X0,h,t):
- x0 = X0[0]
- y0 = X0[1]
- T = 24*60*60
- w_list_x = np.zeros(t*h)
- w_list_y = np.zeros(t*h)
- w_list_x[0] = x0
- w_list_y[0] = y0
- for i in range(1,n):
- R = np.sqrt(w_list_x[i-1]**2+w_list_y[i-1]**2)
- w_list_x[i] = w_list_x[i-1] + h*(2*np.pi*R/T)*(-w_list_y[i-1]/R)
- w_list_y[i] = w_list_y[i-1] + h*(2*np.pi*R/T)*(w_list_x[i-1]/R)
- return w_list_x,w_list_y
- '''def analyticEndPosition(t_end):
- T = 24*60*60
- x_end = L/(1+(4*(np.pi**2)*(t**2))/T)
- y_end = (2*np.pi*t/T)*x_end
- return x_end, y_end'''
- def calcError(h):
- wx,wy= euler(X0,h,t)
- errorSquared = np.abs(wx[0]-wx[t*h-1])**2+np.abs(wy[0]-wy[t*h-1])**2
- return np.sqrt(errorSquared)
- wx,wy= euler(X0,h,t)
- print(wx)
- print(wy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement