[关闭]
@XF 2016-11-27T15:59:14.000000Z 字数 9323 阅读 88

在此处输入标题

作业


一、摘要

二、背景
Earth orbits the Sun,the equation is


From Newton's second law of motion we have

Using astronomical units,1AU is the average distance between the Sun and Earth.1 year is approximately ,We find

We new write each of the second-order differential equations as two first-order differential equations:

If the force go as,the gravitational force is of the form

The planets whose orbits deviate the most from circular are Mercury.The force law predicted by general relativity is

三、正文
1

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import math
  4. beta=[2.01,2.10,2.50,3.00]
  5. x0=0
  6. y0=0
  7. class elliptical:
  8. def __init__(self,e=0.2,GMs=4*math.pi**2,dt=0.0001,time=4):
  9. self.e=e
  10. self.GMs=GMs
  11. self.x1=[1]
  12. self.y1=[0]
  13. self.vx1=[0]
  14. self.vy1=[2*math.pi*math.sqrt(1-self.e)]
  15. self.x2=[1]
  16. self.y2=[0]
  17. self.vx2=[0]
  18. self.vy2=[2*math.pi*math.sqrt(1-self.e)]
  19. self.x3=[1]
  20. self.y3=[0]
  21. self.vx3=[0]
  22. self.vy3=[2*math.pi*math.sqrt(1-self.e)]
  23. self.x4=[1]
  24. self.y4=[0]
  25. self.vx4=[0]
  26. self.vy4=[2*math.pi*math.sqrt(1-self.e)]
  27. self.dt=dt
  28. self.time=time
  29. self.r1=[math.sqrt(self.x1[0]**2+self.y1[0]**2)]
  30. self.r2=[math.sqrt(self.x2[0]**2+self.y2[0]**2)]
  31. self.r3=[math.sqrt(self.x3[0]**2+self.y3[0]**2)]
  32. self.r4=[math.sqrt(self.x4[0]**2+self.y4[0]**2)]
  33. def calculate(self):
  34. for i in range(int(self.time//self.dt)):
  35. self.vx1.append(self.vx1[i]-self.GMs*self.x1[i]*self.dt/self.r1[i]**(beta[0]+1))
  36. self.vy1.append(self.vy1[i]-self.GMs*self.y1[i]*self.dt/self.r1[i]**(beta[0]+1))
  37. self.x1.append(self.x1[i]+self.vx1[i+1]*self.dt)
  38. self.y1.append(self.y1[i]+self.vy1[i+1]*self.dt)
  39. self.r1.append(math.sqrt(self.x1[i+1]**2+self.y1[i+1]**2))
  40. for j in range(int(self.time//self.dt)):
  41. self.vx2.append(self.vx2[j]-self.GMs*self.x2[j]*self.dt/self.r2[j]**(beta[1]+1))
  42. self.vy2.append(self.vy2[j]-self.GMs*self.y2[j]*self.dt/self.r2[j]**(beta[1]+1))
  43. self.x2.append(self.x2[j]+self.vx2[j+1]*self.dt)
  44. self.y2.append(self.y2[j]+self.vy2[j+1]*self.dt)
  45. self.r2.append(math.sqrt(self.x2[j+1]**2+self.y2[j+1]**2))
  46. for i in range(int(self.time//self.dt)):
  47. self.vx3.append(self.vx3[i]-self.GMs*self.x3[i]*self.dt/self.r3[i]**(beta[2]+1))
  48. self.vy3.append(self.vy3[i]-self.GMs*self.y3[i]*self.dt/self.r3[i]**(beta[2]+1))
  49. self.x3.append(self.x3[i]+self.vx3[i+1]*self.dt)
  50. self.y3.append(self.y3[i]+self.vy3[i+1]*self.dt)
  51. self.r3.append(math.sqrt(self.x3[i+1]**2+self.y3[i+1]**2))
  52. for j in range(int(self.time//self.dt)):
  53. self.vx4.append(self.vx4[j]-self.GMs*self.x4[j]*self.dt/self.r4[j]**(beta[3]+1))
  54. self.vy4.append(self.vy4[j]-self.GMs*self.y4[j]*self.dt/self.r4[j]**(beta[3]+1))
  55. self.x4.append(self.x4[j]+self.vx4[j+1]*self.dt)
  56. self.y4.append(self.y4[j]+self.vy4[j+1]*self.dt)
  57. self.r4.append(math.sqrt(self.x4[j+1]**2+self.y4[j+1]**2))
  58. def show_results(self):
  59. ax1=plt.subplot(221)
  60. ax2=plt.subplot(222)
  61. ax3=plt.subplot(223)
  62. ax4=plt.subplot(224)
  63. plt.sca(ax1)
  64. plt.plot(self.x1,self.y1,label='trajectory')
  65. plt.scatter(x0,y0)
  66. plt.title(r'$\beta=2.01$'+ 'Simulation of elliptical orbit',fontsize=10)
  67. plt.xlabel(u'x(AU)',fontsize=10)
  68. plt.ylabel(u'y(AU)',fontsize=10)
  69. plt.sca(ax2)
  70. plt.plot(self.x2,self.y2,label='trajectory')
  71. plt.scatter(x0,y0)
  72. plt.title(r'$\beta=2.10$'+ 'Simulation of elliptical orbit',fontsize=10)
  73. plt.xlabel(u'x(AU)',fontsize=10)
  74. plt.ylabel(u'y(AU)',fontsize=10)
  75. plt.sca(ax3)
  76. plt.plot(self.x3,self.y3,label='trajectory')
  77. plt.scatter(x0,y0)
  78. plt.title(r'$\beta=2.50$'+ 'Simulation of elliptical orbit',fontsize=10)
  79. plt.xlabel(u'x(AU)',fontsize=10)
  80. plt.ylabel(u'y(AU)',fontsize=10)
  81. plt.sca(ax4)
  82. plt.plot(self.x4,self.y4,label='trajectory')
  83. plt.scatter(x0,y0)
  84. plt.title(r'$\beta=3.00$'+ 'Simulation of elliptical orbit',fontsize=10)
  85. plt.xlabel(u'x(AU)',fontsize=10)
  86. plt.ylabel(u'y(AU)',fontsize=10)
  87. plt.xlim(-1,1)
  88. plt.ylim(-1,1)
  89. plt.legend(fontsize=10,loc='best')
  90. a=elliptical()
  91. a.calculate()
  92. a.show_results()
  93. plt.show()

2

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import math
  4. alfa=0.0008
  5. x0=0
  6. y0=0
  7. xp=[]
  8. yp=[]
  9. tp=[]
  10. theta=[]
  11. class elliptical:
  12. def __init__(self,GMs=4*math.pi**2,dt=0.0001,time=2):
  13. self.GMs=GMs
  14. self.x=[0.47]
  15. self.y=[0]
  16. self.vx=[0]
  17. self.vy=[8.2]
  18. self.dt=dt
  19. self.time=time
  20. self.r=[math.sqrt(self.x[0]**2+self.y[0]**2)]
  21. self.t=[0]
  22. def calculate(self):
  23. for i in range(int(self.time//self.dt)):
  24. self.vx.append(self.vx[i]-self.GMs*self.x[i]*self.dt/self.r[i]**3-alfa*self.GMs*self.x[i]*self.dt/self.r[i]**5)
  25. self.vy.append(self.vy[i]-self.GMs*self.y[i]*self.dt/self.r[i]**3-alfa*self.GMs*self.y[i]*self.dt/self.r[i]**5)
  26. self.x.append(self.x[i]+self.vx[i+1]*self.dt)
  27. self.y.append(self.y[i]+self.vy[i+1]*self.dt)
  28. self.t.append(self.t[i]+self.dt)
  29. self.r.append(math.sqrt(self.x[i+1]**2+self.y[i+1]**2))
  30. def precession(self):
  31. for j in range(len(self.r)-2):
  32. if (self.r[j+1]**2-self.r[j]**2>0 and self.r[j+1]**2-self.r[j+2]**2>0):
  33. xp.append(self.x[j+1])
  34. yp.append(self.y[j+1])
  35. tp.append(self.t[j+1])
  36. if self.x[j+1]>=0 and self.y[j+1]/self.x[j+1]>=0:
  37. theta.append(math.atan(self.y[j+1]/self.x[j+1])*180/math.pi)
  38. if self.x[j+1]>=0 and self.y[j+1]/self.x[j+1]<0:
  39. theta.append(math.atan(self.y[j+1]/self.x[j+1])*180/math.pi+360)
  40. if self.x[j+1]<0 and self.y[j+1]/self.x[j+1]>=0:
  41. theta.append(math.atan(self.y[j+1]/self.x[j+1])*180/math.pi+180)
  42. if self.x[j+1]<0 and self.y[j+1]/self.x[j+1]<0:
  43. theta.append(math.atan(self.y[j+1]/self.x[j+1])*180/math.pi+180)
  44. def show_results(self):
  45. for j in range(len(xp)):
  46. plt.plot([0,xp[j]],[0,yp[j]])
  47. plt.plot(self.x,self.y,'g',label=r'$\alpha$=0.0008'+' trajectory')
  48. plt.scatter(x0,y0)
  49. #plt.scatter(tp,theta,label='trajectory')
  50. plt.title(r'$\alpha$=0.0008'+' Simulation of the precession of Mercury ',fontsize=14)
  51. plt.xlabel(u'x(AU)',fontsize=14)
  52. plt.ylabel(u'y(AU)',fontsize=14)
  53. #plt.xlabel(u'time(yr)')
  54. #plt.ylabel(u'$\Theta$(degrees)',fontsize=14)
  55. #plt.xlim(-1,1)
  56. #plt.ylim(-1,1)
  57. plt.legend(fontsize=14,loc='best')
  58. a=elliptical()
  59. a.calculate()
  60. a.precession()
  61. a.show_results()
  62. plt.show()

3

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import math
  4. alfa=[0.0003,0.0005,0.0008,0.0015,0.0035]
  5. xp=[[],[],[],[],[]]
  6. yp=[[],[],[],[],[]]
  7. tp=[[],[],[],[],[]]
  8. theta=[[],[],[],[],[]]
  9. xy=[[],[],[],[],[]]
  10. x2=[[],[],[],[],[]]
  11. x_mean=[]
  12. y_mean=[]
  13. xy_mean=[]
  14. x2_mean=[]
  15. xy1=[]
  16. x21=[]
  17. xf=np.linspace(0,2,200)
  18. yf=[]
  19. class elliptical:
  20. def __init__(self,GMs=4*math.pi**2,dt=0.0001,time=2):
  21. self.GMs=GMs
  22. self.x=[[0.47],[0.47],[0.47],[0.47],[0.47]]
  23. self.y=[[0],[0],[0],[0],[0]]
  24. self.vx=[[0],[0],[0],[0],[0]]
  25. self.vy=[[8.2],[8.2],[8.2],[8.2],[8.2]]
  26. self.dt=dt
  27. self.time=time
  28. self.r=[[math.sqrt(self.x[0][0]**2+self.y[0][0]**2)],[math.sqrt(self.x[0][0]**2+self.y[0][0]**2)],[math.sqrt(self.x[0][0]**2+self.y[0][0]**2)],[math.sqrt(self.x[0][0]**2+self.y[0][0]**2)],[math.sqrt(self.x[0][0]**2+self.y[0][0]**2)]]
  29. self.t=[[0],[0],[0],[0],[0]]
  30. self.a=[]
  31. self.b=[]
  32. def calculate(self):
  33. for n in range(len(alfa)):
  34. for i in range(int(self.time//self.dt)):
  35. self.vx[n].append(self.vx[n][i]-self.GMs*self.x[n][i]*self.dt/self.r[n][i]**3-alfa[n]*self.GMs*self.x[n][i]*self.dt/self.r[n][i]**5)
  36. self.vy[n].append(self.vy[n][i]-self.GMs*self.y[n][i]*self.dt/self.r[n][i]**3-alfa[n]*self.GMs*self.y[n][i]*self.dt/self.r[n][i]**5)
  37. self.x[n].append(self.x[n][i]+self.vx[n][i+1]*self.dt)
  38. self.y[n].append(self.y[n][i]+self.vy[n][i+1]*self.dt)
  39. self.t[n].append(self.t[n][i]+self.dt)
  40. self.r[n].append(math.sqrt(self.x[n][i+1]**2+self.y[n][i+1]**2))
  41. for j in range(len(self.r[n])-2):
  42. if (self.r[n][j+1]**2-self.r[n][j]**2>0 and self.r[n][j+1]**2-self.r[n][j+2]**2>0):
  43. xp[n].append(self.x[n][j+1])
  44. yp[n].append(self.y[n][j+1])
  45. tp[n].append(self.t[n][j+1])
  46. if self.x[n][j+1]>=0 and self.y[n][j+1]/self.x[n][j+1]>=0:
  47. theta[n].append(math.atan(self.y[n][j+1]/self.x[n][j+1])*180/math.pi)
  48. if self.x[n][j+1]>=0 and self.y[n][j+1]/self.x[n][j+1]<0:
  49. theta[n].append(math.atan(self.y[n][j+1]/self.x[n][j+1])*180/math.pi+360)
  50. if self.x[n][j+1]<0 and self.y[n][j+1]/self.x[n][j+1]>=0:
  51. theta[n].append(math.atan(self.y[n][j+1]/self.x[n][j+1])*180/math.pi+180)
  52. if self.x[n][j+1]<0 and self.y[n][j+1]/self.x[n][j+1]<0:
  53. theta[n].append(math.atan(self.y[n][j+1]/self.x[n][j+1])*180/math.pi+180)
  54. for k in range(len(theta[n])):
  55. xy[n].append(tp[n][k]*theta[n][k])
  56. x2[n].append(tp[n][k]**2)
  57. x_mean.append(float(sum(tp[n]))/len(tp[n]))
  58. y_mean.append(float(sum(theta[n]))/len(theta[n]))
  59. xy_mean.append(float(sum(xy[n]))/len(xy[n]))
  60. x2_mean.append(float(sum(x2[n]))/len(x2[n]))
  61. self.a.append(float((xy_mean[n]-x_mean[n]*y_mean[n]))/float((x2_mean[n]-x_mean[n]**2)))
  62. self.b.append(float((x2_mean[n]*y_mean[n]-x_mean[n]*xy_mean[n]))/float((x2_mean[n]-x_mean[n]**2)))
  63. def fit(self):
  64. for k in range(len(alfa)):
  65. xy1.append(alfa[k]*self.a[k])
  66. x21.append(alfa[k]**2)
  67. x_mean1=float(sum(alfa))/len(alfa)
  68. y_mean1=float(sum(self.a))/len(self.a)
  69. xy_mean1=float(sum(xy1))/len(xy1)
  70. x2_mean1=float(sum(x21))/len(x21)
  71. a=float((xy_mean1-x_mean1*y_mean1))/float((x2_mean1-x_mean1**2))
  72. b=float((x2_mean1*y_mean1-x_mean1*xy_mean1))/float((x2_mean1-x_mean1**2))
  73. print a,b
  74. for m in range(len(xf)):
  75. yf.append(a*xf[m]+b)
  76. def show_results(self):
  77. plt.plot(xf,yf,'g',label='least-squares line')
  78. plt.scatter(alfa,self.a,label='scatter')
  79. plt.title(u'Simulation of the precession of Mercury',fontsize=14)
  80. plt.xlabel(u'alpha',fontsize=14)
  81. plt.ylabel(u'$d\Theta/dt$(degrees/yr)',fontsize=14)
  82. plt.xlim(0,0.005)
  83. plt.ylim(0,60)
  84. plt.legend(fontsize=14,loc='best')
  85. a=elliptical()
  86. a.calculate()
  87. a.fit()
  88. a.show_results()
  89. plt.show()

四、结论
改变时


改变时时,行星轨道基本无变化。
三、致谢
感谢杜威同学对我本次作业的帮助!

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