[R-sig-dyn-mod] DDEs in simecol?
Thomas Petzoldt
thomas.petzoldt at tu-dresden.de
Tue Jul 2 18:19:04 CEST 2013
Hello James,
yes this is possible if you specify a user-defined solver function. This
is easy, because for class odeModel, simecol is just an object oriented
wrapper for package deSolve, that does the real work.
If you use simecol or plain deSolve has its pros and cons and is a
matter of taste. deSolve alone is a little bit easier, but simecol can
help to make to applications more structured, e.g. in case of model
comparisons.
Thomas
### Simple DDE, adapted version of ?dede
### example from package deSolve
library(simecol)
model <- new("odeModel",
main = function(t, y, parms) {
with(as.list(parms), {
if (t < tau)
ytau <- 1
else
ytau <- lagvalue(t - tau)
dy <- k * ytau
list(c(dy), ytau=ytau)
})
},
init = c(y=1),
times = seq(0, 30, 0.1),
parms = c(tau = 1, k = -1),
solver = function(init, times, func, parms) {
dede(init, times, func, parms)
}
)
model <- sim(model)
plot(model, main = c("dy/dt = -y(t-1)", "ytau"))
More information about the R-sig-dynamic-models
mailing list