[R-sig-dyn-mod] tolerance or choice of solver question

Thomas Petzoldt Thomas.Petzoldt at TU-Dresden.de
Tue Aug 27 22:30:51 CEST 2013


Hi,

this is a classical case, because your time step vector "times" is 
irregular.

Solution:

set hmax = 0.05 (or to a smaller value).

times <- c(seq(0, 40, by = 0.01), 41)

ode(y = state, times = times, func = derivs, parms = pars,
   method="lsoda",rtol = 1e-8, atol =1e-8, hmax=0.05)


... so that short term forcings are not "overlooked".


The documentation tells us:

"hmax 	an optional maximum value of the integration stepsize. If not 
specified, hmax is set to the largest difference in times, to avoid that 
the simulation possibly ignores short-term events. If 0, no maximal size 
is specified."

This means that

times <- c(seq(0, 41, by = 0.01))

would also work without setting hmax.


Other possible options are:

1) to use the explicit event mechanism (see ?events). This was designed 
for short term pulses and is more efficient.

OR:

2) make your pulses smooth, as discussed in a thread on this list 2 
months ago (2013-06-24).

Hope it helps,

Thomas



More information about the R-sig-dynamic-models mailing list