在Python中用延时求解ODE

2024-10-03 04:34:15 发布

您现在位置:Python中文网/ 问答频道 /正文

有谁能给我一些建议,如何用Python解决一个实现了延时的ODE?我好像不知道怎么用scipy.integrate.odeint. 我要找的应该是:

# the constants in the equation
b = 1/50
d = 1/75
a = 0.8
G = 10 ** (-2)
tau = 0.5
u = [b, d, tau, a, G]

# enter initial conditions
N0 = 0.1
No0 = 10
w = [N0, No0]

def logistic(w, t, u):
    N, No = w
    b, d, tau, a, G = u
    dNdt = b * (No(t) - N(t) ) * (N(t) / No(t) ) - d * N(t - tau)
    dNodt = G * (a * No(t) - N(t) ) * (N(t) / No(t) )
    return [dNdt, dNodt]

# create timescale
# create timescale
stoptime = 1000.0
numpoints = 10000
t = np.linspace(0, stoptime, numpoints)

# in my previous code I would use scipy.integrate.odeint here to integrate my 
# equations, but with a time-delay that doesn't work (I think)
soln = ...

其中N(t)、N(t-tau)等表示函数的时间参数。有没有一个好的库来解决这些类型的方程?先谢谢你!在


Tags: thenoincreatescipyintegratetaun0
1条回答
网友
1楼 · 发布于 2024-10-03 04:34:15

我是JiTCDDE的作者,这本书可以解延迟微分方程,并且大部分类似于{}。你可以用pip3 install jitcdde安装它。据我所知,其他现有的用于Python的DDE库要么已损坏,要么基于不推荐的依赖项。在

以下代码将集成您的问题:

from jitcdde import t, y, jitcdde
import numpy as np

# the constants in the equation
b = 1/50
d = 1/75
a = 0.8
G = 10**(-2)
tau = 0.5

# the equation
f = [    
    b * (y(1) - y(0)) * y(0) / y(1) - d * y(0, t-tau),
    G * (a*y(1) - y(0)) * y(0) / y(1)
    ]

# initialising the integrator
DDE = jitcdde(f)

# enter initial conditions
N0 = 0.1
No0 = 10
DDE.add_past_point(-1.0, [N0,No0], [0.0, 0.0])
DDE.add_past_point( 0.0, [N0,No0], [0.0, 0.0])

# short pre-integration to take care of discontinuities
DDE.step_on_discontinuities()

# create timescale
stoptime = 1000.0
numpoints = 100
times = DDE.t + np.linspace(1, stoptime, numpoints)

# integrating
data = []
for time in times:
    data.append( DDE.integrate(time) )

相关问题 更多 >