我有一个大学项目,我们被要求使用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) 未定义。 –