使用时间延迟解决Python中的ODE [英] Solve ODE in Python with a time-delay

查看:174
本文介绍了使用时间延迟解决Python中的ODE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我一些建议,如何解决在Python中实现了时间延迟的ODE吗?我似乎无法弄清楚如何使用scipy.integrate.odeint.我要寻找的应该是这样的:

Can anybody give me some advice how to solve an ODE in Python that has a time-delay implemented in it? I can't seem to figure out how to do it using scipy.integrate.odeint. What I am looking for should look like:

# 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)等表示函数的时间参数.是否存在一个好的库可以解决这些类型的方程式?提前非常感谢!

Where the N(t), N(t - tau) etc. indicate the time arguments of the functions. Does a good library exist to solve these types of equations? Many thanks in advance!

推荐答案

我是 JiTCDDE 的作者,可以求解延迟微分方程,并且大多数类似于scipy.ode.您可以使用pip3 install jitcdde进行安装.据我所知,其他现有的Python DDE库已损坏或基于已过时的依赖关系.

I am the author of JiTCDDE, which can solve delay differential equations and is mostly analogous to scipy.ode. You can install it, e.g., with pip3 install jitcdde. As far as I know, the other existing DDE libraries for Python are either broken or based on deprecated dependencies.

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

The following code would integrate your problem:

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中的ODE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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