[关闭]
@ibilis 2016-12-04T11:01:10.000000Z 字数 1037 阅读 434

code

未分类


  1. from math import pi,sqrt,sin,cos
  2. import matplotlib.pyplot as plt
  3. def hyperion(theta0):
  4. # set the mass of saturn
  5. gm=4*pi**2
  6. # initialize position of center of mass, angle, angle velocity
  7. xc=[1]
  8. yc=[0]
  9. theta=[theta0]
  10. avelo=[0]
  11. vxc=[0]
  12. vyc=[5]
  13. # get the trails
  14. dt=0.0001
  15. t=[0]
  16. while t[-1]<=15:
  17. r=sqrt((xc[-1])**2+(yc[-1])**2)
  18. vxc_new=vxc[-1]-gm*xc[-1]*dt/r**3
  19. vyc_new=vyc[-1]-gm*yc[-1]*dt/r**3
  20. avelo_new=avelo[-1]-12*(pi**2)*(xc[-1]*sin(theta[-1])-yc[-1]*cos(theta[-1]))*(xc[-1]*cos(theta[-1])+yc[-1]*sin(theta[-1]))*dt/r**5
  21. vxc.append(vxc_new)
  22. vyc.append(vyc_new)
  23. avelo.append(avelo_new)
  24. xc.append(xc[-1]+vxc[-1]*dt)
  25. yc.append(yc[-1]+vyc[-1]*dt)
  26. theta_new=theta[-1]+avelo[-1]*dt
  27. if theta_new<-pi :
  28. theta_new=theta_new+2*pi
  29. elif theta_new>pi :
  30. theta_new=theta_new-2*pi
  31. else :
  32. pass
  33. theta.append(theta_new)
  34. t.append(t[-1]+dt)
  35. return theta,t
  36. t=hyperion(0)[1]
  37. the1=hyperion(0)[0]
  38. the2=hyperion(0.01)[0]
  39. dthe=[]
  40. for i in range(len(the1)):
  41. dthe.append(abs(the2[i]-the1[i]))
  42. plt.plot(t,dthe)
  43. plt.semilogy(t,dthe)
  44. plt.title('delta theta vs time')
  45. plt.xlabel('time(yr)')
  46. plt.ylabel('dtheta(radians)')
  47. plt.xlim(0,10)
  48. plt.show()
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注