JiTCDDE problems with integration

221 Views Asked by At

I'm trying to solve a 2D delay differential equation with some parameters. The problem is that I can’t get the right solution (which I know) and I suspect that it comes from the integration step, but I'm not sure and I don't really understand how the JiTCDDE works.

This is the DDE:

enter image description here

This is my model:

def model(p, q, r, alpha, T, tau, tmax, ci):
    f = [1/T * (p*y(0)+alpha*y(1, t-tau)), 1/T * (r*y(0)+q*y(1))]
            
    DDE = jitcdde(f)
    
    
    DDE.constant_past(ci)
    
    DDE.step_on_discontinuities()
    
         
    data = []
    for time in np.arange(DDE.t, DDE.t+tmax, 0.09):
        data.append( DDE.integrate(time)[1])
    return data

Where I'm only interested in the y(1) solution

And the parameters:

T=32        #escala temporal
p=-2.4/T
q=-1.12/T
r=1.5/T
alpha=.6/T
tau=T*2.4     #delay
tmax=400
ci = np.array([4080, 0])

This is the plot I have with that model and parameters:

enter image description here

And this is (the blue line) the correct solution (someone give me the plot not the data)

enter image description here

1

There are 1 best solutions below

5
Wrzlprmft On

The following code works for me and produces a result similar to your control:

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

T = 1
p = -2.4/T
q = -1.12/T
r = 1.5/T
alpha = .6/T
tau = T*2.4
tmax = 10
ci = np.array([4080, 0])

f = [
        1/T * (p*y(0)+alpha*y(1, t-tau)),
        1/T * (r*y(0)+q*y(1))
    ]

DDE = jitcdde(f)
DDE.constant_past(ci)
DDE.adjust_diff()

times = np.linspace( DDE.t, DDE.t+tmax, 1000 )
values = [DDE.integrate(time)[1] for time in times]

from matplotlib.pyplot import subplots
fig,axes = subplots()
axes.plot(times,values)
fig.show()

Note the following:

  • I set T=1 (and adjusted tmax accordingly). I presume that there still is a mistake here.

  • I used adjust_diff instead of step_on_discontinuities. The problem with your model is that it has a heavy discontinuity in the derivative at t=0. (A discontinuity is normal, but none of this kind). This causes problems with the adaptive step size control at the very beginning of the integration. Such a discontinuity suggests that there is something wrong with either your model or your initial past. The latter doesn’t matter if you only care about long-term behaviour, but this doesn’t seem to be the case here. I added a passage to the documentation about this kind of issue.