Python - 在ODE中使用带有积分的odeint

问题描述 投票:0回答:1

我正在使用以下形式的ODE:

a * dv / dt +(b + k1)* v + c * integral_0-> t_(vdt)= k1 * v1 + k2 * integral_0-> t_(v1dt)

我正在尝试实现odeint以获得该系统的解决方案,但我不确定如何使用ODE中的积分来实现。 v1是已知输入,因此右侧的积分不是问题。

python scipy ode differential-equations integral
1个回答
1
投票

x设置为v的积分,使x'=vx''=v',类似x1v1,使你的方程读作二阶微分方程

a*x''+(b+k1)*x'+c*x=k1*v1+k2*x1

给定v1作为输入,状态向量需要包含三个集成变量x, v, x1,它给出了ODE函数

def odesys(y,t):
    x, v, x1 = y
    v1 = eval_v1(t)
    return [ v, (k1*v1+k2*x1 - (b+k1)*v-c*x )/a, v1 ]

要与odeint一起使用,您可以这样做

t = np.linspace(0,T,2001); # define the end time T before
y0 = [ 0, 0, 0 ]           # standard convention is that everything is zero for negative times
y = odeint(odesys, y0, t)  # add arguments for higher accuracy if needed
x, v, x1 = y.T             # transpose of a list of tuples is a tuple of lists
plt.plot(t,x); plt.show()  # as example that should work
© www.soinside.com 2019 - 2024. All rights reserved.