[关闭]
@zy-0815 2016-11-27T17:41:31.000000Z 字数 3961 阅读 1050

计算物理第十次作业Problem4.8


摘要

上次作业研究了桌球的碰撞问题,而此次作业将重点放在了大家熟悉又陌生的太阳系中。
image_1b2j8dtssf3aa6t16rl1va9109t9.png-619kB

背景

已知在天体运动中天体遵循万有引力定律:


将太阳运动分解为x,y轴方向可以得到:

由Euler-Cromer方法可以处理上面式子,并取初始条件为x=a(1+e),y=0,同时有:
image_1b2j9p3tgueq198qdk3m2i1e6pm.png-10.3kB
此时一个简单的模型已经出来了,但不足之处有未考虑相对论等效应。

正文

1. 行星椭圆运动

程序为:

  1. import pylab as pl
  2. import math
  3. class Solar_system :
  4. def __init__(self,i=0,initial_x=1,initial_y=0,initial_vx=0,initial_vy=2*math.pi,\
  5. total_time=10, time_step=0.002, radius=1):
  6. self.x=[initial_x]
  7. self.y=[initial_y]
  8. self.vx=[initial_vx]
  9. self.vy=[initial_vy]
  10. self.r=[radius]
  11. self.time=total_time
  12. self.dt=time_step
  13. self.t=[0]
  14. def run(self):
  15. _time=0
  16. while(_time<self.time):
  17. self.vx.append(self.vx[-1]-4*pow(math.pi,2)*self.x[-1]/pow(self.r[-1],3)*self.dt)
  18. self.x.append(self.x[-1]+self.vx[-1]*self.dt)
  19. self.vy.append(self.vy[-1]-4*pow(math.pi,2)*self.y[-1]/pow(self.r[-1],3)*self.dt)
  20. self.y.append(self.y[-1]+self.vy[-1]*self.dt)
  21. self.t.append(_time)
  22. _time += self.dt
  23. def show_results(self):
  24. pl.plot(self.x,self.y)
  25. pl.title('Solar system')
  26. pl.xlabel('x(AU)')
  27. pl.ylabel('y(AU)')
  28. pl.legend()
  29. pl.show()
  30. a = Solar_system()
  31. a.run()
  32. a.show_results()

运行结果为:
image_1b2jba59s1fqt1uq0fqtkg115qj9.png-12.4kB
当改变e值时即可改变轨道形状,可得结果:
image_1b2jbhpjj7pkqkdp00bb6rtem.png-25.4kB

2 不同β运动轨迹

以水星为例,取β=2、2.01、2.1、2.5的轨道轨迹,程序如下:

  1. import pylab as pl
  2. import math
  3. def initial(a,e,MP,beta):
  4. MS=2*10**(30)
  5. x0=a*(1+e)
  6. y0=0
  7. vx0=0
  8. vy0=2*math.pi*math.sqrt((1-e)/(a*(1+e))*(1+MP/MS))
  9. return [x0,y0,vx0,vy0,beta]
  10. class orbits():
  11. def __init__(self,x0,y0,vx0,vy0,beta):
  12. self.x=[x0]
  13. self.y=[y0]
  14. self.vx=[vx0]
  15. self.vy=[vy0]
  16. self.dt=0.001
  17. self.t=[0]
  18. self.steps=2000
  19. self.r=[]
  20. self.beta=beta
  21. def calculate(self):
  22. for i in range(self.steps):
  23. self.r.append(math.sqrt(self.x[i]**2+self.y[i]**2))
  24. temp_vx=self.vx[i]-4*math.pi**2*self.x[i]*self.r[i]**(-self.beta-1)*self.dt
  25. self.vx.append(temp_vx)
  26. temp_x=self.x[i]+self.vx[i+1]*self.dt
  27. temp_vy=self.vy[i]-4*math.pi**2*self.y[i]*self.r[i]**(-self.beta-1)*self.dt
  28. self.vy.append(temp_vy)
  29. temp_y=self.y[i]+self.vy[i+1]*self.dt
  30. self.x.append(temp_x)
  31. self.y.append(temp_y)
  32. self.t.append(self.t[i]+self.dt)
  33. return self.x,self.y
  34. def show_result(self):
  35. pl.plot(self.x,self.y,".")
  36. pl.xlabel('x(AU)')
  37. pl.ylabel('y(AU)')
  38. pl.xlim(-1,1)
  39. pl.ylim(-1,1)
  40. pl.title("Mercury,beita=2")
  41. pl.grid(True)
  42. pl.show()
  43. I=initial(0.39,0.206,2.4*10**(23),2)
  44. a=orbits(I[0],I[1],I[2],I[3],I[4])
  45. a.calculate()
  46. a.show_result()

运行结果为:
image_1b2jc28im1aae72post9qf1h4l13.png-12.3kB
改变β值即有:
image_1b2jc5vmutd91hapmu3b3v1j5t1g.png-12.8kB
image_1b2jc7gdfmt1isnba1k0t9v71t.png-17.6kB
image_1b2jc8nd313l7ko2jrb13d1uji2a.png-23.4kB

3 验证开普勒第三定律与理想值的比较

程序为:

  1. import pylab as pl
  2. import math
  3. def initial(a,e,MP):
  4. MS=2*10**(30)
  5. x0=a*(1+e)
  6. y0=0
  7. vx0=0
  8. vy0=2*math.pi*math.sqrt((1-e)/(a*(1+e))*(1+MP/MS))
  9. return [x0,y0,vx0,vy0]
  10. class orbits():
  11. def __init__(self,x0,y0,vx0,vy0):
  12. self.x=[x0]
  13. self.y=[y0]
  14. self.vx=[vx0]
  15. self.vy=[vy0]
  16. self.dt=0.001
  17. self.t=[0]
  18. self.steps=300001
  19. self.r=[]
  20. self.x2=[]
  21. self.y2=[]
  22. self.t2=[]
  23. def calculate(self):
  24. for i in range(self.steps):
  25. self.r.append(math.sqrt(self.x[i]**2+self.y[i]**2))
  26. temp_vx=self.vx[i]-4*math.pi**2*self.x[i]*self.r[i]**(-3)*self.dt
  27. self.vx.append(temp_vx)
  28. temp_x=self.x[i]+self.vx[i+1]*self.dt
  29. temp_vy=self.vy[i]-4*math.pi**2*self.y[i]*self.r[i]**(-3)*self.dt
  30. self.vy.append(temp_vy)
  31. temp_y=self.y[i]+self.vy[i+1]*self.dt
  32. self.x.append(temp_x)
  33. self.y.append(temp_y)
  34. self.t.append(self.t[i]+self.dt)
  35. if self.y[i+1]<0:
  36. self.y2.append(self.y[i+1])
  37. self.x2.append(self.x[i+1])
  38. self.t2.append(self.t[i+1])
  39. a=(self.x[0]-self.x2[0])/2
  40. T=self.t2[0]*2
  41. print(a,T,T**2/a**3)
  42. return self.x,self.y,self.x2,self.y2
  43. def show_result(self):
  44. pl.plot(self.x,self.y,".")
  45. pl.xlabel('x(AU)')
  46. pl.ylabel('y(AU)')
  47. pl.xlim(-1.5,1.5)
  48. pl.ylim(-1.5,1.5)
  49. pl.title('simulation of elliptical orbit')
  50. pl.show()
  51. I_v=initial(0.72,0.007,4.9*10**(24))
  52. v=orbits(I_v[0],I_v[1],I_v[2],I_v[3])
  53. v.calculate()
  54. v.show_result()
  55. I_e=initial(1,0.017,6*10**(24))
  56. e=orbits(I_e[0],I_e[1],I_e[2],I_e[3])
  57. e.calculate()
  58. e.show_result()
  59. I_ma=initial(1.52,0.093,6.6*10**(23))
  60. ma=orbits(I_ma[0],I_ma[1],I_ma[2],I_ma[3])
  61. ma.calculate()
  62. ma.show_result()
  63. I_j=initial(5.2,0.048,1.9*10**(27))
  64. j=orbits(I_j[0],I_j[1],I_j[2],I_j[3])
  65. j.calculate()
  66. j.show_result()
  67. I_s=initial(9.54,0.056,5.7*10**(26))
  68. s=orbits(I_s[0],I_s[1],I_s[2],I_s[3])
  69. s.calculate()
  70. s.show_result()

运行结果为:
image_1b2jd2gdc1c5f15e42ese58sfi2n.png-6.9kB

结论

由上面运行结果可以看出基本可以模拟出行星运动的轨迹,同时也可以开普勒第三定律验证时与理想值还是有一定差距的,而误差来源可能是每一步的时间距离以及点数选取太少。

致谢

感谢陆文龙同学的耐心帮助。

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