我有一個大學項目,我們被要求使用ODE和SciPy的odeint函數來模擬火星的衛星方法。解決ODE的python時的錯誤
我設法通過將二階ODE分解爲兩個一階ODE來模擬2D。然而,由於我的代碼使用SI單元,因此我停留在時間限制內,因此在幾秒鐘內運行,而Python的內部空間限制甚至不能模擬一個完整的軌道。
我試着將變量和常量轉換成小時和公里,但現在代碼不斷給出錯誤。
我跟着這個方法:
http://bulldog2.redlands.edu/facultyfolder/deweerd/tutorials/Tutorial-ODEs.pdf
而且代碼:
import numpy
import scipy
from scipy.integrate import odeint
def deriv_x(x,t):
return array([ x[1], -55.3E10/(x[0])**2 ]) #55.3E10 is the value for G*M in km and hours
xinit = array([0,5251]) # this is the velocity for an orbit of period 24 hours
t=linspace(0,24.0,100)
x=odeint(deriv_x, xinit, t)
def deriv_y(y,t):
return array([ y[1], -55.3E10/(y[0])**2 ])
yinit = array([20056,0]) # this is the radius for an orbit of period 24 hours
t=linspace(0,24.0,100)
y=odeint(deriv_y, yinit, t)
我不知道如何複製/粘貼PyLab錯誤代碼,所以我花了PRINTSCREEN的錯誤:
第二誤差具有t = linspace(0.01,24.0,100)和xinit的=陣列([0.001,5251):
如果任何人有關於如何提高代碼任何建議我會很感激。
非常感謝!
您將需要顯示您所得到的確切錯誤。 – BrenBarn
我剛編輯原帖。謝謝! – user1937000
是否重要 deriv_x(xinit,0) 未定義。 –