[英]Third order differential equation in python
https://docs.scipy.org/doc/scipy-0.18.1/reference/generation/scipy.integrate.ode.html
这里是您要搜索的库,如果您向下滚动底部,也有一些示例。 阅读愉快
您的解决方案可能看起来像这样(如果删除所有与绘图相关的线,则该长度很短)
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.