[关闭]
@2014301020081 2016-11-27T14:35:08.000000Z 字数 1911 阅读 465

The tenth homework of computational physics about of noncircular orbits of 4.8

defeng kong 2014301020081


Abstract

Background

4.8

Verify Kepler's third law for elliptical orbits.Run the planetary motion program with initial conditions chosen to give orbits that are noncircular.Calculate and compare with the values given in Table 4.2.

The main body and conclusion

the code is:

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. class noncircular():
  4. def __init__(self,e,a,y0,vx0,M_P,M_S,dt):
  5. self.e=e
  6. self.a=a
  7. self.x = e*a+a
  8. self.y = y0
  9. self.vx =vx0
  10. self.M_P = M_P
  11. self.M_S = M_S
  12. self.vy = np.sqrt(4*np.pi**2*(1-self.e)*(1+self.M_P/self.M_S)/(self.a*(1+self.e)))
  13. self.t=0
  14. self.dt=dt
  15. self.tra_x = [a]
  16. self.tra_y = [y0]
  17. self.W=0
  18. self.b=1
  19. def calculate(self):
  20. for i in range(30000):
  21. self.r=np.sqrt(self.x**2+self.y**2)
  22. self.vx=self.vx-4*np.pi**2*self.x*self.dt/self.r**3
  23. self.vy=self.vy-4*np.pi**2*self.y*self.dt/self.r**3
  24. self.x=self.x+self.vx*self.dt
  25. self.y=self.y+self.vy*self.dt
  26. self.tra_x.append(self.x)
  27. self.tra_y.append(self.y)
  28. self.t=self.t+self.dt
  29. def run_trajectory(self):
  30. self.W = (0.001*2*np.pi*max(self.tra_x)*max(self.tra_y)\
  31. /((self.e*self.a+self.a)*self.tra_y[1]))**2/self.a**3
  32. print self.W
  33. plt.axis('equal')
  34. plt.ylim(-max(self.tra_y),max(self.tra_y))
  35. plt.xlabel('x(AU)')
  36. plt.ylabel('y(AU)')
  37. #plt.title('Simulation of circular orbit ')
  38. plt.title('Simulation of elliptical orbit ')
  39. plt.text(0,0.5,'T^2/a^3=1.11520692458')
  40. plt.plot(self.tra_x,self.tra_y,'.')
  41. plt.show()
  42. A=noncircular(0.056,9.54,0,0,5.7*10**26,2.0*10**30,0.001)
  43. A.calculate()
  44. A.run_trajectory()

For circular orbit:
for Venus:
此处输入图片的描述
for Earth:
此处输入图片的描述
for Mars(Venus in plot is wrong):
此处输入图片的描述
for Jupiter:
此处输入图片的描述
for Saturn:
此处输入图片的描述
For elliptical orbit
for Venus:
此处输入图片的描述
for Earth(Venus in plot is wrong):
此处输入图片的描述
for Mars(Venus in plot is wrong):
此处输入图片的描述
for Jupiter:
此处输入图片的描述
for Saturn:
此处输入图片的描述
so for circular orbit(the value of T^2/a^3):
Venus:0.9898
Earth:0.9938
Mars:0.9967
Jupiter:1.0004
Saturn:1.00007
For elliptical orbit:(the value of T^2/a^3)
Venus:1.0039
Earth:1.0280
Mars:1.1913
Jupiter:1.0987
Saturn:1.1152
We can see the value is close to 1 for circular orbit and elliptical orbit.

Thanks

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注