简体   繁体   English

Python中的三阶微分方程

[英]Third order differential equation in python

I am new to Python so that at this time, I can only very basic problems. 我是Python的新手,所以目前我只能解决一些非常基本的问题。

How do I solve an ODE like this in Python? 如何在Python中解决这样的ODE?

在此处输入图片说明

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

Here the library you are searching for, if you scroll down on the bottom there are some examples too. 这里是您要搜索的库,如果您向下滚动底部,也有一些示例。 Have a nice reading 阅读愉快

Your solution could look like this (if you remove all plot related lines, it is quite short) 您的解决方案可能看起来像这样(如果删除所有与绘图相关的线,则该长度很短)

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.

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