[R] lsoda question from deSolve package

Thomas Petzoldt thpe at simecol.de
Mon Apr 22 07:47:26 CEST 2013


Hi Andreas,

adding a varying amount of something over time is even easier than 
implementing an "immediate" event. It can be implemented as a "forcing", 
see ?forcings and example below.

Hope it helps,

Thomas


require(deSolve)

pkmod <- function(t, y, p) {
   inp <- forc(t)

   if (t < tin) R <- (D/tin) else R <- 0
   dy1 <- R - (p["k12"]+p["k"])* y[1] + p["k21"]*y[2]   + inp
   dy2 <- p["k12"]* y[1] - p["k21"] *y[2]
   list(c(dy1, dy2), inp=inp)
}

## an example, not your data
intimes <- c(0, 2, 5, 10, 24)
input   <- c(0, 200, 100, 0, 0)
forc <- approxfun(intimes, input, method="constant")

times <- seq(0, 24, 0.1)
tin  <- 0.5
D    <- 400
V    <- 26.3
yini <- c(Central = 0, Peripheral = 0)
p    <- c(k=0.05, k12=0.197118, k21=0.022665, V=26.3)

result <- lsoda(yini, times, pkmod, p, rtol = 1e-08, atol = 1e-08)
plot(result)


-- 
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-help mailing list