Exercise_10: The Solar System

We begin with the simplest situation,a sun and a single planet,and investigate a few of the properties of this model solar system.

solar system.gif

solar system.gif

According to Newton's law of gravitation the magnitude of the force is given by

![](http://latex.codecogs.com/png.latex?F_G=\frac{G M_S M_E}{r^2})

and we can obtain that:

![](http://latex.codecogs.com/png.latex?\frac{dv_x}{dt}=-\frac{GM_s M_E x}{r^3})


![](http://latex.codecogs.com/png.latex?\frac{dv_y}{dt}=-\frac{GM_s y}{r^3})

and if we use astronomical units ,AU; and measure time in years, we find

![](http://latex.codecogs.com/png.latex?G M_S=v^2 r=4 \pi^2 AU2/yr2)

we next convert the equations of motion into difference equations in preparation for constructing a computational solution.We find

![](http://latex.codecogs.com/png.latex?v_{x,i+1}=v_{x,i}-\frac{4\pi^2 x_i}{r_i^3}\Delta t)
![](http://latex.codecogs.com/png.latex?x_{i+1}=x_i +v_{x,i+1}\Delta t)
![](http://latex.codecogs.com/png.latex?v_{y,i+1}=v_{y,i}-\frac{4\pi^2 y_i}{r_i^3}\Delta t)
![](http://latex.codecogs.com/png.latex?y_{i+1}=y_i+v_{y,i+1}\Delta t)

and I imitate it by python ,and I gained that:

Earth Orbiting the Sun

code1触菜,as follows:

#coding:utf-8
import pylab as pl
import numpy as np
import math
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import animation

class circle():
    def __init__(self,x0=1,y0=0,t0=0,vx0=0,vy0=2*math.pi,dt0=0.001,total_time=10):
        self.x=[x0]
        self.y=[y0]
        self.vx=[vx0]
        self.vy=[vy0]
        self.R=x0**2+y0**2
        self.t=[t0]
        self.dt=dt0
        self.T=total_time
    def run(self):
        for i in range(int(self.T/self.dt)):
            vx=self.vx[-1]-(4*math.pi**2*self.x[-1]/self.R**2)*self.dt
            vy=self.vy[-1]-(4*math.pi**2*self.y[-1]/self.R**2)*self.dt
            self.vx.append(vx)
            self.vy.append(vy)
            self.x.append(self.vx[-1] * self.dt + self.x[-1])
            self.y.append(self.vy[-1] * self.dt + self.y[-1])
    def show(self):
        pl.plot(self.x, self.y, '-', label='tra')
        pl.xlabel('x(AU)')
        pl.ylabel('y(AU)')
        pl.title('Earth orbiting the Sun')
        pl.xlim(-1.2,1.2)
        pl.ylim(-1.2,1.2)
        pl.axis('equal')
        pl.show()
a=circle()
a.run()
a.show()

we can use the animation of matplotlib to gain the cartoon,

add follow codes:

 def drawtrajectory(self):
        fig=plt.figure()
        ax = plt.axes(title=('Earth orbiting the Sun'),
                      aspect='equal', autoscale_on=False,
                      xlim=(-1.1, 1.1), ylim=(-1.1, 1.1),
                      xlabel=('x'),ylabel=('y'))
        line=ax.plot([],[],'b')
        point=ax.plot([],[],'ro',markersize=10)
        images=[]
        def init():
            line=ax.plot([],[],'b',markersize=8)
            point=ax.plot([],[],'ro',markersize=10)
            return line,point
        def anmi(i):
            ax.clear()
            line=ax.plot(self.x[0:10*i],self.y[0:10*i],'b',markersize=8)
            point=ax.plot(self.x[10*i-1:10*i],self.y[10*i-1:10*i],'ro',markersize=10)
            return line,point
        anmi=animation.FuncAnimation(fig,anmi,init_func=init,frames=10000,interval=1,
                                     blit=False,repeat=False)

we get follow gif

Earth Orbiting the Sun

If we consider the reduced mass

![](http://latex.codecogs.com/png.latex?\mu\equiv \frac{m1m2}{m1+m2})

The orbital trajectory for a body of reduced mass is given in polar coordinates by

![](http://latex.codecogs.com/png.latex?\frac{d^2}{dt ^2} (\frac{1}{r})+\frac{1}{r}=-\frac{\mu r2}{L2} F(r))
consider


we have
![](http://latex.codecogs.com/png.latex?r=(\frac{L^2}{\mu G M_s M_P} )\frac{1}{1-e cos\theta })
so

Then let us suppose that the gravitational force is of the form

![](http://latex.codecogs.com/png.latex?F_G=\frac{GM_S M_E}{r^{\beta}})
then I get
![](http://latex.codecogs.com/png.latex?v_{x,i+1}=v_{x,i}-\frac{4\pi^2 x_i}{r_i^{\beta+1}}\Delta t)
![](http://latex.codecogs.com/png.latex?x_{i+1}=x_i +v_{x,i+1}\Delta t)
![](http://latex.codecogs.com/png.latex?v_{y,i+1}=v_{y,i}-\frac{4\pi^2 y_i}{r_i^{\beta+1}}\Delta t)
![](http://latex.codecogs.com/png.latex?y_{i+1}=y_i+v_{y,i+1}\Delta t)

the picture


Beta=3.0 t=0.3yr v=1.7pi.png
Beta=2.5艺栈,t=1.5yr,v=1.7pi.png
Beta=2.3,t=10yr,v=1.7pi.png

code

#coding:utf-8
import pylab as pl
import numpy as np
import math
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import animation

class circle():
    def __init__(self,x0=1,y0=0,t0=0,vx0=0,vy0=1.7*math.pi,dt0=0.001,Beta=2.3,total_time=10):
        self.x=[x0]
        self.y=[y0]
        self.vx=[vx0]
        self.vy=[vy0]
        self.t=[t0]
        self.dt=dt0
        self.T=total_time
        self.beta=Beta
    def run(self):
        for i in range(int(self.T/self.dt)):
            R=(self.x[-1]**2+self.y[-1]**2)**0.5
            vx=self.vx[-1]-(4*math.pi**2*self.x[-1]/R**(self.beta+1))*self.dt
            vy=self.vy[-1]-(4*math.pi**2*self.y[-1]/R**(self.beta+1))*self.dt
            self.vx.append(vx)
            self.vy.append(vy)
            self.x.append(self.vx[-1] * self.dt + self.x[-1])
            self.y.append(self.vy[-1] * self.dt + self.y[-1])
    def show(self):
        pl.plot(self.x, self.y, '-', label='tra')
        pl.xlabel('x(AU)')
        pl.ylabel('y(AU)')
        pl.title('Earth orbiting the Sun')
        pl.xlim(-1,1)
        pl.ylim(-1,1)
        pl.axis('equal')
        pl.show()
    def drawtrajectory(self):
        fig=plt.figure()
        ax = plt.axes(title=('Earth orbiting the Sun '),
                      aspect='equal', autoscale_on=False,
                      xlim=(-1.1, 1.1), ylim=(-1.1, 1.1),
                      xlabel=('x'),ylabel=('y'))
        line=ax.plot([],[],'b')
        point=ax.plot([],[],'ro',markersize=10)
        images=[]
        def init():
            line=ax.plot([],[],'b',markersize=8)
            point=ax.plot([],[],'ro',markersize=10)
            return line,point
        def anmi(i):
            ax.clear()
            line=ax.plot(self.x[0:10*i],self.y[0:10*i],'b',markersize=8)
            point=ax.plot(self.x[10*i-1:10*i],self.y[10*i-1:10*i],'ro',markersize=10)
            return line,point
        anmi=animation.FuncAnimation(fig,anmi,init_func=init,frames=100000,interval=1,
                                     blit=False,repeat=False)
        plt.show()


a=circle()
a.run()
a.show()
#a.drawtrajectory()

then we get the animation

Beta=3.0,v=2.0pi,t=200yr

for the problem 4.8, I use the follow code to calculate

import pylab as pl
import numpy as np
import math
class circle():
    def __init__(self,x0=0.72,y0=0,t0=0,vx0=0,dt0=0.001,Beta=2.0,total_time=10,e0=0.007):
        self.x=[x0]
        self.y=[y0]
        self.vx=[vx0]
        self.vy=[]
        self.t=[t0]
        self.dt=dt0
        self.T=total_time
        self.beta=Beta
        self.e=e0

    def run(self):
        vy0=2*math.pi*(1-self.e)/math.sqrt(1+self.e)
        self.vy.append(vy0)
        for i in range(int(self.T/self.dt)):
            R=(self.x[-1]**2+self.y[-1]**2)**0.5
            vx=self.vx[-1]-(4*math.pi**2*self.x[-1]/R**(self.beta+1))*self.dt
            vy=self.vy[-1]-(4*math.pi**2*self.y[-1]/R**(self.beta+1))*self.dt
            self.vx.append(vx)
            self.vy.append(vy)
            self.x.append(self.vx[-1] * self.dt + self.x[-1])
            self.y.append(self.vy[-1] * self.dt + self.y[-1])
            self.t.append(self.t[-1]+self.dt)
            if(self.y[-1]<0):
                a=(self.x[0]-self.x[-1])/2
                T=2*self.t[-1]
                k=T**2/a**3
                break
        print(k)
a=circle()
a.run()

For Venus诡曙, I just get the value

and others can just be got by the similar way 2333

Acknowledgements

Thanks for Nemo's or (盧江瑋的) help

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末埋哟,一起剝皮案震驚了整個(gè)濱河市笆豁,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖闯狱,帶你破解...
    沈念sama閱讀 221,635評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件煞赢,死亡現(xiàn)場離奇詭異,居然都是意外死亡哄孤,警方通過查閱死者的電腦和手機(jī)照筑,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,543評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來瘦陈,“玉大人凝危,你說我怎么就攤上這事∷ⅲ” “怎么了媒抠?”我有些...
    開封第一講書人閱讀 168,083評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長咏花。 經(jīng)常有香客問我趴生,道長,這世上最難降的妖魔是什么昏翰? 我笑而不...
    開封第一講書人閱讀 59,640評(píng)論 1 296
  • 正文 為了忘掉前任苍匆,我火速辦了婚禮,結(jié)果婚禮上棚菊,老公的妹妹穿的比我還像新娘浸踩。我一直安慰自己,他們只是感情好统求,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,640評(píng)論 6 397
  • 文/花漫 我一把揭開白布检碗。 她就那樣靜靜地躺著,像睡著了一般码邻。 火紅的嫁衣襯著肌膚如雪折剃。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,262評(píng)論 1 308
  • 那天像屋,我揣著相機(jī)與錄音怕犁,去河邊找鬼。 笑死己莺,一個(gè)胖子當(dāng)著我的面吹牛奏甫,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播凌受,決...
    沈念sama閱讀 40,833評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼阵子,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了胜蛉?” 一聲冷哼從身側(cè)響起款筑,我...
    開封第一講書人閱讀 39,736評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤智蝠,失蹤者是張志新(化名)和其女友劉穎腾么,沒想到半個(gè)月后奈梳,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,280評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡解虱,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,369評(píng)論 3 340
  • 正文 我和宋清朗相戀三年攘须,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片殴泰。...
    茶點(diǎn)故事閱讀 40,503評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡于宙,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出悍汛,到底是詐尸還是另有隱情捞魁,我是刑警寧澤,帶...
    沈念sama閱讀 36,185評(píng)論 5 350
  • 正文 年R本政府宣布离咐,位于F島的核電站谱俭,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏宵蛀。R本人自食惡果不足惜昆著,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,870評(píng)論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望术陶。 院中可真熱鬧凑懂,春花似錦、人聲如沸梧宫。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,340評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽塘匣。三九已至脓豪,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間馆铁,已是汗流浹背跑揉。 一陣腳步聲響...
    開封第一講書人閱讀 33,460評(píng)論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留埠巨,地道東北人历谍。 一個(gè)月前我還...
    沈念sama閱讀 48,909評(píng)論 3 376
  • 正文 我出身青樓,卻偏偏與公主長得像辣垒,于是被迫代替她去往敵國和親望侈。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,512評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容