使用 scipy odeint 求解耦合微分方程组

编程入门 行业动态 更新时间:2024-10-10 19:26:44
本文介绍了使用 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] ])

函数deriv 以Y = [y, y'] 作为输入.

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

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

y' = Y[1]

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

更多推荐

使用 scipy odeint 求解耦合微分方程组

本文发布于:2023-11-30 06:16:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方程组   微分   scipy   odeint

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!