ddeint icon indicating copy to clipboard operation
ddeint copied to clipboard

Incosistency with the solution of odeint when time delay is zero

Open ChengMa-RPI opened this issue 5 years ago • 6 comments

Hi,

I have a problem about the solution given by ddeint when time delay is set to zero. I expect in this case that the solution is the same as that solved by odeint package. However, there are small deviations from the result of odeint when time delay is zero.

For my dynamc system, I expect the evolution converges to stable states without time delay, which is observed using odeint.

Here is my dynamics: dx/dt = 0.1 + x * (1-x(t-\tau)/5) * (x-1) + 4 * x**2 / (5 + x); \tau is time delay. If it is set zero, then x should converge to some constant. But the solution given by ddeint dose not converge to a stable state.

Thanks for any help!

Michael

ChengMa-RPI avatar Jan 27 '20 20:01 ChengMa-RPI

Can you share a minimal code?

Zulko avatar Jan 27 '20 20:01 Zulko

Hi Zulko,

Thanks for your reply!

Here is my code,

import numpy as np
from ddeint import ddeint
from scipy.integrate import odeint 

def dynamics_dde(f, t, d1):
    x = f(t)
    xd1 = f(t-d1)
    dxdt = 0.1 + x * (1 -xd1/5) * (x - 1) + 4 * x * x / (5 + x)
    return dxdt

def dynamics_ode(x, t):
    dxdt = 0.1 + x * (1 -x/5) * (x - 1) + 4 * x * x / (5 + x)
    return dxdt

g = lambda t: 5  # x(t) = 5 for t<0
t = np.arange(0, 100,0.01)  # simulation time 
d = (0,)  # time delay 
x0 = 5  #initial condition for odeint 
result_dde = ddeint(dynamics_dde, g, t, fargs=d)
result_ode = odeint(dynamics_ode, x0, t) 

deviation = result_dde - result_ode[:,0]  

ChengMa-RPI avatar Jan 27 '20 22:01 ChengMa-RPI

On my computer I obtain this. It looks acceptable to me, the solutions are the same with some slight numercal imprecision in the very first points:

image

Zulko avatar Jan 27 '20 22:01 Zulko

Yes, I obtained the same result. They are roughtly the same. But what I worry about is that the result given by ddeint changes with time. It seems there is small perturbation adding to the system. I am afraid that when the time delay is large enough, such effect will be magnified.

But anyway, thanks for your test and great help!

ChengMa-RPI avatar Jan 27 '20 23:01 ChengMa-RPI

The only way to get better convergence in ddeint is to reduce your time step, e.g. from 0.01 to 0.005

Zulko avatar Jan 27 '20 23:01 Zulko

Thanks! Small time step gives better convergence. The deviation pattern is kind of interesting. Hope it can be solved in the future if you are interested.

ChengMa-RPI avatar Jan 27 '20 23:01 ChengMa-RPI