python - 用时间延迟在 Python 中求解 ODE

标签 python ode differential-equations timedelay

谁能给我一些建议,告诉我如何用 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) 等表示函数的时间参数。是否存在一个很好的库来解决这些类型的方程式?非常感谢!

最佳答案

我是 JiTCDDE 的作者,它可以求解延迟微分方程,主要类似于 scipy.ode。您可以安装它,例如,使用 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) )

关于python - 用时间延迟在 Python 中求解 ODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42632523/

相关文章:

python - 使用 Python 将 XML 文档插入现有 XML

c++ - 如果我还需要使用 ODE,我应该从 Eigen 切换到 MTL4 吗?

c# - .net 中最好的免费常微分方程库

python - scipy.integrate.ode.integrate() 是如何工作的?

python - "Two-to-many"与 Flask-SQLAlchemy 的关系

python - 如何为另一个字符串封装字符串?

Redshift中的Python UDF函数总是返回NULL值

julia - 用隐式欧拉和共轭梯度线性求解器求解非零狄利克雷 BC 的热方程?

python - 如何更好地使用 Cython 更快地求解微分方程?

julia - Julia 中的二阶 ODE 给出了错误的结果