Closed ChengMa-RPI closed 2 months ago
Can you share a minimal code?
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]
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:
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!
The only way to get better convergence in ddeint is to reduce your time step, e.g. from 0.01 to 0.005
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.
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