如何在python中设置三个主体问题?如何定义函数来解决ODE?在Python中绘制轨道轨迹
三个方程是
x'' = -mu/np.sqrt(x ** 2 + y ** 2 + z ** 2) * x
,
y'' = -mu/np.sqrt(x ** 2 + y ** 2 + z ** 2) * y
,并
z'' = -mu/np.sqrt(x ** 2 + y ** 2 + z ** 2) * z
。
写为6阶,我们有
x' = x2
,
y' = y2
,
z' = z2
,
x2' = -mu/np.sqrt(x ** 2 + y ** 2 + z ** 2) * x
,
y2' = -mu/np.sqrt(x ** 2 + y ** 2 + z ** 2) * y
和
z2' = -mu/np.sqrt(x ** 2 + y ** 2 + z ** 2) * z
我也想在路径中添加地图轨道和火星,我们可以假设它是圆形的。 地球距离太阳149.6 * 10 ** 6
公里,火星227.9 * 10 ** 6
公里。
#!/usr/bin/env python
# This program solves the 3 Body Problem numerically and plots the trajectories
import pylab
import numpy as np
import scipy.integrate as integrate
import matplotlib.pyplot as plt
from numpy import linspace
mu = 132712000000 #gravitational parameter
r0 = [-149.6 * 10 ** 6, 0.0, 0.0]
v0 = [29.0, -5.0, 0.0]
dt = np.linspace(0.0, 86400 * 700, 5000) # time is seconds
特别是你要问什么?如果你有更具体的问题,人们可能会更有可能提供帮助。 – askewchan
@askewchan我不知道如何输入6个一阶ODE作为函数,因为'integrate.odeint'只会取一阶方程。 – dustin
您可以使用'integrate.ode'来求解高阶方程。 – askewchan