Solve_ivp输出,进入轨道图?

问题描述

我正在尝试使用重力加速度绘制围绕木星的卫星轨道。 我似乎无法确定如何正确使用resolve_ivp函数。只是没有点击...我为月球创建了ODE,与原点的木星有关。

year = np.arange(0,31536000,3600)
G = 6.67408e-11
jupiter_xpos = 0
jupiter_ypos = 0
jupiter_vel = (0,0)
jupiter_mass = 1.89819e27
Io_orbit = 421700000
Io_xpos = -421700000
Io_ypos = 0
Io_xvel = 0
Io_yvel =  -1773400
Io_mass = 8.9319e22
Io = [Io_xpos,Io_xvel,Io_ypos,Io_yvel]


def ode(Moon,t_max):
    #Moon[0,1,2,3]=[x,v_x,y,v_y]
    output=[0,0]
    R = ((Moon[0]**2 + Moon[2]**2)**(3/2))
    output[0]=Moon[1]
    output[1]= -G*jupiter_mass*Moon[0]/R
    output[2]=Moon[3]
    output[3]= -G*jupiter_mass*Moon[2]/R
    return output

#This is where the problem is
sol= solve_ivp(ode,Io,year)


plt.plot(sol[:,0],sol[:,2],'ro')
plt.axis('equal')
plt.grid(True)
plt.show()

我希望获得这样的2D轨道图...

enter image description here

并跟踪和绘制x和y位置和速度随时间的每个变化。

解决方法

solve_ivp的文档显示参数为

sol = solve_ivp(ode,[t0,tf],u0,tspan=year,atol = 100,rtol=1e-9)

其中year=np.arange(t0,tf,hour)。然后,您在sol.t中找到重复值的解值,并在sol.y中找到值。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...