ODE events

## =============================================================================
## R-Code to solve example 3.4.1.2 from the book
## K. Soetaert, J. Cash and F. Mazzia, 2012.  
## Solving differential equations in R. UseR, Springer, 248 pp. 
## http://www.springer.com/statistics/computational+statistics/book/978-3-642-28069-6.
## implemented by Karline Soetaert
## =============================================================================

## An ordinary differential equation model with events

b    <- 0.6
yini <- c(blood = 0)

pharmaco2 <- function(t, blood, p) {
  dblood <-  - b * blood
  list(dblood)
}

injectevents <- data.frame(var = "blood",
                          time =  0:20,
                          value = 40,
                          method = "add")
head(injectevents, n=3)

times <- seq(from = 0, to = 10, by = 1/24)

out2 <- ode(func = pharmaco2, times = times, y = yini, 
           parms = NULL, method = "impAdams", 
           events = list(data = injectevents))

plot(out2, lwd = 2)

Go back