2016-12-14 119 views
-1

我是Python的新手,所以在这个时候,我只能有非常基本的问题。python中的三阶微分方程

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

enter image description here

+4

使用'scipy.integrate.odeint'或'scipy.integrate.ode' 。这两个python包都有很好的教程页面。完成后,通过编辑问题添加一些您尝试的代码。这就证明了你对这一切有多了解,那么明智的答案是可能的。 – LutzL

+0

“我只能有非常基本的问题。”我必须知道:你认为ODE是一个“非常基本的问题”吗?如果不是,那么你对我们的期望是什么样的帮助?如果是的话,那么到底什么是你的难题? –

回答

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