[R-sig-dyn-mod] problem with DDE
Thomas Petzoldt
Thomas.Petzoldt at TU-Dresden.de
Thu Apr 11 21:05:45 CEST 2013
David,
this happens if you try to access past values that don't exist yet or
that cannot be interpolated from accumulated data in the history buffer.
See ?lagvalue that tells us: "the lagged time should not be smaller than
the initial simulation time, nor should it be larger than the current
simulation time."
The solution is to catch this condition in the model function and and to
provide default values. Just try the example example below with and
without the outcommented lines.
Hope it helps
Thomas P.
----------------------------------------------------------------------
library(deSolve)
derivs <- function(t, y, parms) {
cat("t=", t, "\n")
with(as.list(c(y, parms)), {
#if (t < tau)
# ytau <- c(1, 1)
#else
ytau <- lagvalue(t - tau, c(1, 2))
dN <- f * N - g * N * P
dP <- e * g * ytau[1] * ytau[2] - m * P
list(c(dN, dP), tau=ytau[1], tau=ytau[2])
})
}
yinit <- c(N=1, P=1)
times <- seq(0, 100, 10)
parms <- c(f=0.1, g=0.2, e=0.1, m=0.1, tau = .2)
yout <- dede(y = yinit, times = times, func = derivs, parms = parms)
--
Thomas Petzoldt
Technische Universitaet Dresden
Faculty of Environmental Sciences
Institute of Hydrobiology
01062 Dresden, Germany
http://tu-dresden.de/Members/thomas.petzoldt
More information about the R-sig-dynamic-models
mailing list