Skip to content
Prev 668 / 696 Next

[R-sig-dyn-mod] Problem with dede's lagvalue (deSolve)

Hi Nicola,

the error indicates that the history buffer is exhausted. You can 
increase the buffer by setting mxhist:

y_out_2 <- dede(y = yinit, times = times_sd, func = supplydrive,
                 parms = parms_sd, method = "lsoda",
                 control = list(mxhist = 1e6))

This is found on the ` ?dede help page.

Unfortunately, this solves only part of the problem in your case, 
because then the solver seems to get stuck due to numerical problems. 
Some of the states grow exponentially to extreme values.

To see this, you can put a print or cat in the model function:

cat("time=", t, ", slag=", slag, ", llag=", llag, ",
     taulag=", taulag, "\n")

... or you can try a brute-force simulation with another solver, e.g. 
"vode" and a modified absolute tolerance (either a large value or zero). 
The relative tolerance remains unchanged.

times_sd <- seq(0, 500, by = 1)
y_out_2 <- dede(y = yinit, times = times_sd, func = supplydrive,
                 parms = parms_sd, method = "vode",
                 control = list(mxhist = 1e6), atol = 0)

plot(y_out_2)

The output contains then at least part of the solution and the plot 
shows where the it ran into trouble. Setting the time step to a larger 
value (e.g. by=1) speeds up simulation, because a too small time step 
just limits internal step size adaptation.

Thomas
On 10.03.2022 at 19:06 Nicola Gambaro wrote: