Guest User

Untitled

a guest
Feb 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. time = 60
  5. dt = 0.001
  6. m = 0.1
  7. g = 9.81
  8. theta = 5*np.pi/6
  9. k = 200
  10. L0 = 1
  11. r = np.zeros((n,2),float)
  12. v = np.zeros((n,2),float)
  13. a = np.zeros((n,2),float)
  14. t = np.zeros((n,1),float)
  15. n = int(np.ceil(time/dt))
  16. r0 = np.array([L0*np.sin(theta) ,L0*np.cos(theta) ])
  17. v0 = np.array([1.0, 0.0])
  18. r[0,:] = r0
  19. v[0,:] = v0
  20.  
  21.  
  22. for i in range(n):
  23. a[i,:] = (-m*g*np.array[0,1]-k*(((r[i,0])**2+(r[i,1])**2)-L0))/m*(r[i,0] /((r[i,0])**2+(r[i,1])**2))
  24.  
  25. v[i+1,:] = v[i,:] + a[i,:]*dt
  26. r[i+1,:] = r[i,:] + v[i+1,:]*dt
  27.  
  28. plt.plot(r[1:i, 0], r[1:i, 1])
  29. plt.show()
Add Comment
Please, Sign In to add comment