使用 scipy odeint 求解耦合微分方程组 [英] Solving system of coupled differential equations using scipy odeint

查看:77
本文介绍了使用 scipy odeint 求解耦合微分方程组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 odeint 有点困惑.

我在下面找到了一个例子来解决 y"=ay + by'.所以看起来 y[0] 是函数,y[1] 是一阶导数.

I found one example below to solve y"=ay + by'. So it seems that y[0] is the function, y[1] is the first derivative.

下面的表达式是否意味着 y[1] =y'y'[1]= a*y[0]+b*y[1]?

So does the following expression mean y[1] =y' and y'[1]= a*y[0]+b*y[1] ?

如果是y[2], a*y[0]+b*y[1],它是什么意思?

If it were y[2], a*y[0]+b*y[1], what would it mean?

我有点困惑,因为表达式没有说等式的左侧.

I am a bit confused since the expression does not say the left hand side of the equation.

我也遇到过像[a(y[0], y[1]), b(y[0], y[1])]之类的表达式,但对微分方程一无所知.

I also encountered expressions like [a(y[0], y[1]), b(y[0], y[1])] but have no clue of the differential equation.

这是一个例子:

from scipy.integrate import odeint
from pylab import * # for plotting commands

def deriv(y,t): # return derivatives of the array y
    a = -2.0
    b = -0.1
    return array([ y[1], a*y[0]+b*y[1] ])

time = linspace(0.0,10.0,1000)
yinit = array([0.0005,0.2]) # initial values
y = odeint(deriv,yinit,time)
figure()
plot(time,y[:,0])
xlabel('t')
ylabel('y')
show()

推荐答案

让我们在 deriv 中使用 Y 而不是 y 用于其余部分答案要明确:

Let's use Y in deriv instead of y for the rest of answer to be clear:

def deriv(Y,t): # return derivatives of the array Y
    a = -2.0
    b = -0.1
    return array([ Y[1], a*Y[0]+b*Y[1] ])

函数derivY = [y, y'] 作为输入.

它应该输出它们的导数([y', y'']).

And it should output their derivatives ([y', y'']).

y' = Y[1]

y'' = a*Y[0]+b*Y[1]

这篇关于使用 scipy odeint 求解耦合微分方程组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆