[英]scipy.odeint returning incorrect values for second order non-linear differential equation
我一直在嘗試求解牛頓萬有引力定律(平方反比定律)的二階非線性微分方程:
x(t)'' = -GM/(x**2)
一維衛星接近地球(在這種情況下為點質量)的運動
使用numpy.odeint和一系列一階微分方程,但是與Mathematica或簡化形式的定律(∆x =(1/2)at ^ 2)相比,該運算未得到正確的結果。
這是程序的代碼:
import numpy as np
from scipy.integrate import odeint
def deriv(x, t): #derivative function, where x[0] is x, x[1] is x' or v, and x2 = x'' or a
x2 = -mu/(x[0]**2)
return x[1], x2
init = 6371000, 0 #initial values for x and x'
a_t = np.linspace(0, 20, 100) #time scale
mu = 398600000000000 #gravitational constant
x, _ = odeint(deriv, init, a_t).T
sol = np.column_stack([a_t, x])
當衛星從6371000 m(地球的平均半徑)的初始距離接近地球時,它會產生一個具有a_t和x位置值耦合的數組。 例如,人們可能希望該物體從6371000m下降到6370000m大約需要10秒才能從地面墜落1000 m(因為對1000 = 1/2(9.8)(t ^ 2)的解幾乎是10),微分方程的數學解決方案也將該值設置為略高於10s。
然而,根據odeint解和sol陣列的值接近14.4。
t x
[ 1.41414141e+01, 6.37001801e+06],
[ 1.43434343e+01, 6.36998975e+06],
odeint解決方案中是否存在重大錯誤,或者我的功能/ odeint使用方面是否存在重大問題? 謝謝!
(因為解到1000 = 1/2(9.8)(t ^ 2)幾乎是10),
這是正確的健全性檢查,但是您的算法有些不正確。 使用這種近似,我們得到了一個t
的
>>> (1000 / (1/2 * 9.8))**0.5
14.285714285714285
而不是約10的距離,這只會給我們一個距離
>>> 1/2 * 9.8 * 10**2
490.00000000000006
預期〜14.29非常接近您觀察到的結果:
>>> sol[abs((sol[:,1] - sol[0,1]) - -1000).argmin()]
array([ 1.42705427e+01, 6.37000001e+06])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.