Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib import animation
  4. from numpy import sin
  5.  
  6.  
  7. def calculate(omd):
  8. t=np.array([20],dtype=float)
  9. th=np.array([],dtype=float)
  10. om=np.array([],dtype=float)
  11. e=np.array([0],dtype=float)
  12.  
  13.  
  14.  
  15. th0=0.05 #float(input("Give initial angle"))
  16. time=50 #float(input("Give total time"))
  17. om0=0
  18. dt=0.05 #float(input("Give time step"))
  19. l=1 #float(input("Give length of string"))
  20. n=int(time/dt)
  21. q=1
  22. omd=omd
  23. th=np.append(th,th0)
  24. om=np.append(om,om0)
  25. for i in range(n):
  26. #ANGULAR VELOCITY:
  27. temp1=om[i]-((9.8/l)*th[i]+q*om[i]-1*sin(omd*t[i]))*dt
  28.  
  29. #ANGLE:
  30. temp2=th[i]+temp1*dt
  31.  
  32. #TIME:
  33. t=np.append(t,50+(i+1)*dt)
  34.  
  35. #ENERGY:
  36. temp3=e[i]+0.5*9.8*l*(om[i]**2+(9.8/l)*th[i]**2)*dt**2
  37.  
  38. om=np.append(om,temp1)
  39. th=np.append(th,temp2)
  40. e=np.append(e,temp3)
  41.  
  42. amp=(np.amax(th)-np.min(th))/2
  43.  
  44.  
  45. return amp
  46.  
  47.  
  48. omda=np.linspace(0,X,1000) #X is the max value I want to look for, (20 or 0.5)
  49.  
  50. def om_iter(ampa,omda):
  51. for i in omda:
  52. temp1=calculate(i)
  53. ampa=np.append(ampa,temp1)
  54. return ampa,omda
  55.  
  56.  
  57. ampa=np.array([],dtype=float)
  58. ampa,omda=om_iter(ampa,omda)
  59.  
  60. plt.plot(omda,ampa)
  61. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement