简体   繁体   English

scipy.odeint为二阶非线性微分方程返回错误值

[英]scipy.odeint returning incorrect values for second order non-linear differential equation

I have been trying to solve the second order non-linear differential equation for Newton's Law of Universal Gravitation (inverse square law): 我一直在尝试求解牛顿万有引力定律(平方反比定律)的二阶非线性微分方程:

x(t)'' = -GM/(x**2)

for the motion of a satellite approaching the earth (in this case a point-mass) in one dimension 一维卫星接近地球(在这种情况下为点质量)的运动

MS Paint技能

using numpy.odeint with a series of first order differential equations, but the operation has been yielding incorrect results when compared to Mathematica or to simplified forms of the law (∆x = (1/2)at^2). 使用numpy.odeint和一系列一阶微分方程,但是与Mathematica或简化形式的定律(∆x =(1/2)at ^ 2)相比,该运算未得到正确的结果。

This is the code for the program: 这是程序的代码:

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])

which yields an array with coupled a_t and x position values as the satellite approaches the earth from an initial distance of 6371000 m (the average radius of the earth). 当卫星从6371000 m(地球的平均半径)的初始距离接近地球时,它会产生一个具有a_t和x位置值耦合的数组。 One would expect, for instance, that the object would take approximately 10 seconds to fall 1000 m at the surface from 6371000m to 6370000m (because the solution to 1000 = 1/2(9.8)(t^2) is almost exactly 10), and the mathematica solution to the differential equation puts the value at slightly above 10s as well. 例如,人们可能希望该物体从6371000m下降到6370000m大约需要10秒才能从地面坠落1000 m(因为对1000 = 1/2(9.8)(t ^ 2)的解几乎是10),微分方程的数学解决方案也将该值设置为略高于10s。

数学解决方案

Yet that value according the odeint solution and the sol array is nearly 14.4. 然而,根据odeint解和sol阵列的值接近14.4。

  t                    x
  [  1.41414141e+01,   6.37001801e+06],
  [  1.43434343e+01,   6.36998975e+06],

pylab图

Is there significant error in the odeint solution, or is there a major problem in my function/odeint usage? odeint解决方案中是否存在重大错误,或者我的功能/ odeint使用方面是否存在重大问题? Thanks! 谢谢!

(because the solution to 1000 = 1/2(9.8)(t^2) is almost exactly 10), (因为解到1000 = 1/2(9.8)(t ^ 2)几乎是10),

This is the right sanity check, but something's off with your arithmetic. 这是正确的健全性检查,但是您的算法有些不正确。 Using this approximation, we get a t of 使用这种近似,我们得到了一个t

>>> (1000 / (1/2 * 9.8))**0.5
14.285714285714285

as opposed to at of ~10, which would give us only a distance of 而不是约10的距离,这只会给我们一个距离

>>> 1/2 * 9.8 * 10**2
490.00000000000006

This expectation of ~14.29 is very close to the result you observe: 预期〜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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM