建國高中特色選修課程 - 物理現象的程式設計與模擬
作者:賴奕帆
日期:2018/8/01
同學們,在看參考解之前,請先想清楚自己是否真的有花時間想過如何寫課堂作業和進階作業了呢?
學習無他,但求自己覺得好玩而已。
若真的想把一件事情學好,務必花時間才能掌握。
希望這邊的作業參考解法,真的都只是讓同學們拿來參考,而不是為了繳交作業的複製貼上。
想過了嗎? 那請認真參考吧。
利用前述的圖表,討論衛星在橢圓運動中,是否有遵守力學能守恆。
註:在衛星空間尺度中,由於萬有引力不是定值,因此衛星與地球間的位能公式應為
"""更改圖表 (2. 畫面設定)"""
gd = graph(align='left',width=400,height=400,
title='K+U=E', xtitle='t', ytitle='E(red) , K(black) , U(green)',
foreground=color.black,background=color.white,
xmax=1*10**5, xmin=0, ymax=4*10**10, ymin=-4*10**10)
f1 = gcurve(color=color.red)
f2 = gcurve(color=color.black)
f3 = gcurve(color=color.green)
"""計算衛星運動中的動能、位能與總力學能 (3. 執行迴圈)"""
materK = 0.5*m*(____________________________________) #動能
materU = -G*M*m/dist #位能
materE = materK+materU #總力學能
"""將動能、位能與總力學能匯入圖表 (3. 執行迴圈)"""
f1.plot(pos=(t,________))
f2.plot(pos=(t,________))
f3.plot(pos=(t,________))
再加入兩個衛星,讓三個衛星有不同的初速,觀察整體的運動狀況。
"""再加入兩個衛星 (2. 畫面設定)"""
mater2 = sphere(pos=vec(H,0,0), radius=0.1*Re,color=color.blue, make_trail=True)
mater2v = ______________
mater3 = sphere(pos=vec(H,0,0), radius=0.1*Re,color=color.yellow, make_trail=True)
mater3v = ______________
"""計算mater2與mater3的引力 (3. 執行迴圈)"""
dist2 = ((mater2.pos.x-earth.pos.x)**2+____________________________
radiavector2 = (mater2.pos-earth.pos)/dist2
Fg_vector2 = Fg(dist2)*radiavector2
mater2v += ____________/m*dt
mater2.pos = mater2.pos + _________*dt
利用三點紀錄法找出衛星運動的週期。
"""計算衛星運動週期(1. 參數設定)"""
T = 0
"""在迴圈中計算衛星運動週期(3. 執行迴圈)"""
T = T+dt
"""在迴圈中計算衛星運動週期(3. 執行迴圈)"""
if pre_mater_pos.x > pre_pre_mater_pos.x and pre_mater_pos.x > mater.pos.x :
print (mater.pos , T , t) #修改
T = 0
##if pre_mater_pos.x < pre_pre_mater_pos.x and pre_mater_pos.x < mater.pos.x :
## print (mater.pos)
##if pre_mater_pos.y > pre_pre_mater_pos.y and pre_mater_pos.y > mater.pos.y :
## print (mater.pos)
##if pre_mater_pos.y < pre_pre_mater_pos.y and pre_mater_pos.y < mater.pos.y :
## print (mater.pos)
請在衛星運動中,加入速度與加速度(分解為
"""繪製速度向量(紅色)與加速度向量(黃色)(2. 畫面設定)"""
v_arrow = arrow(pos=mater.pos,axis=vec(0,0,0),shaftwidth=0.4*mater.radius ,color = color.red)
a_arrow = arrow(pos=mater.pos,_____________________________)
"""讓速度箭頭與加速度箭頭,隨著衛星一起運動(3. 執行迴圈)"""
v_arrow.pos = mater.pos
v_arrow.axis = materv*2*10**3 #乘2*10**3 #為了讓動畫的速度向量顯著
a_arrow.pos = mater.pos
a_arrow.axis = Fg/m*5*10**6 #乘 5*10**6 #可自行調整大小
"""繪製切線加速度與法線加速度(2. 畫面設定)"""
aT_arrow = arrow(pos=mater.pos,axis=vec(0,0,0),shaftwidth=0.6*mater.radius ,color = color.black)
aN_arrow = arrow(pos=mater.pos,axis=vec(0,0,0),shaftwidth=0.6*mater.radius ,color = color.blue)
"""讓切線加速度箭頭與法線加速度箭頭,隨著衛星一起運動(3. 執行迴圈)"""
aT_arrow.pos = mater.pos
aT_arrow.axis = dot(Fg/m,materv)*(norm(materv)/mag(materv))*5*10**6
aN_arrow.pos = mater.pos
aN_arrow.axis = (mag(cross(Fg/m,materv))/mag(materv))*cross(norm(materv),vector(0,0,-1))*5*10**6
請嘗試驗證克卜勒行星第三定律。
克卜勒行星第三定律又稱週期定律。
定律內容:『各行星若繞同一恆星時,其公轉週期的平方與行星到太陽平均距離的三次方成正比。』
物理公式:
此為克卜勒以大量觀察數據歸納出的,後來牛頓以行星受到萬有引力當作向心力來驗證其結果。
"""找地球右端點位置,算k1 = r1^3/T1^2(3. 執行迴圈)"""
if pre_earth_pos.x > pre_pre_earth_pos.x and pre_earth_pos.x > earth.pos.x :
earth_T = t1 #設定earth_T為地球週期
print (' k1 = r1^3/T1^2 = ', R_sun_earth**3/earth_T**2) #列印結果
t1=0 #時間重置
"""找地球左端點位置(3. 執行迴圈)"""
if pre_earth_pos.x < pre_pre_earth_pos.x and pre_earth_pos.x < earth.pos.x :
earth_left_point = earth.pos.x #紀錄地球最左端點
"""找地球右端點位置,算k1 = r1^3/T1^2"""
if pre_earth_pos.x > pre_pre_earth_pos.x and pre_earth_pos.x > earth.pos.x :
earth_right_point = earth.pos.x #紀錄地球最右端點
earth_a = (abs(earth_right_point)+abs(earth_left_point))/2 #計算橢圓下半長軸
earth_T = t1 #設定earth_T為地球週期 #設定earth_T為地球週期
print (' k1 = r1^3/T1^3 = ', earth_a**3/earth_T**2) #列印結果
t1=0 #時間重置