0

I'm integrating the following differential equation

enter image description here

with this code using JiTCDDE:

def model(p, q, r, alpha, T, tau, tmax, ci, step):
    f = [(p*y(0)+alpha*y(1, t-tau)), (r*y(0)+q*y(1))]
        
    DDE = jitcdde(f)


    DDE.constant_past(ci)

    DDE.adjust_diff()

     
    data = []
    for time in np.arange(DDE.t, DDE.t+tmax, step):
        data.append( DDE.integrate(time)[1])
    return data

and with this parameters

T=3        #escala temporal
p=-2.4/T
q=-1.12/T
r=1.5/T
alpha=.4/T
tau=T*2.4     #delay
tmax=30
step = 1
ci = np.array([1300, 0])

My trouble is that when I plot the data obtained by

data = model(p, q, r, alpha, T, tau, tmax, ci, step)

I get a very not smooth profile at the maximum like this:

enter image description here

and when I change the integration step to 0.1 I get this

enter image description here

but that plot goes to 300 instead of 30 which is what I would like

the question is: is there any way to integrate the equation up to t=30 but smoothed like the one that goes to t=300 ? Can I do that by onlye changing the parameters ??

Wrzlprmft
  • 4,234
  • 1
  • 28
  • 54
DiegoT
  • 29
  • 6

1 Answers1

1

The problem is that model does not return the sampling times (np.arange(DDE.t, DDE.t+tmax, step)), but you simply assume them to be equidistant with a gap of 1 when plotting. That is wrong once you change step to 0.1.

So, what you have to do is something like this:

def model(…):
    …
    data = []
    times = np.arange(DDE.t, DDE.t+tmax, step)
    for time in times:
        data.append( DDE.integrate(time)[1])
    return times, data

and then (assuming you plot with Matplotlib):

times,data = model(…)
axes.plot(times,data)
Wrzlprmft
  • 4,234
  • 1
  • 28
  • 54