python中的三阶微分方程

时间:2016-12-14 11:23:07

标签: python ode

我是Python的新手,所以在这个时候,我只能解决非常基本的问题。

如何在Python中解决这样的ODE?

enter image description here

2 个答案:

答案 0 :(得分:2)

https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.integrate.ode.html

这里是您要搜索的库,如果您在底部向下滚动,也会有一些示例。读得很好

答案 1 :(得分:0)

您的解决方案可能如下所示(如果删除所有与绘图相关的行,则很短)

import numpy as np
from scipy.integrate import odeint
import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as pl

# define the ODE as a first order system
def func(y,x):
    return [ 
        y[1], 
        y[2], 
        ( 7*x**1.5 - 5*x**2*y[2]-2*x*y[1] + 2*y[0]) / x**3 
        ]    

# initial values
y0=[ 10.6, -3.6, 31.2]
# points at which the solution value is requested
x = np.linspace(1,10,501)
# numerical integration
y=odeint(func, y0, x)
# y[-1,:] contains the value at x=10
print "[ y(10), y'(10), y''(10) ] = ", y[-1,:]

# plot the solution with subplots for each component
fig=pl.figure()
ax=fig.add_subplot(311)
ax.plot(x, y[:,0])
ax=fig.add_subplot(312)
ax.plot(x, y[:,1])
ax=fig.add_subplot(313)
ax.plot(x, y[:,2])
pl.show()