[R-sig-dyn-mod] deSolve events - different event functions at different times
Tom.Sumner at lshtm.ac.uk
Tom.Sumner at lshtm.ac.uk
Fri Jan 25 16:05:57 CET 2013
Dear list,
I am using deSolve to solve a set of ODEs and am trying to make use of the events mechanism. Is there a way to apply two different events (defined as functions) at different times?
Using an example from the inside-R documentation to illustrate:
# Derivative function
derive <- function(t, var, parms){
list(c(0,-0.5 *var[2]))
}
# events
event1 <- function(t,y,parms){
with (as.list(y),{
v1 <- v1 + 1
v2 <- 5 * runif(1)
})
}
event2 <- function(t,y,parms){
with (as.list(y),{
v1 <- v1 + 0.5*y2
v2 <- 5 * runif(1)
})
}
yini <- c(v1 = 1, v2 = 2)
times <- seq(0, 10, by 0.1)
out <- ode(func = derivs, y =yini, times = times, parms = NULL,
events = list(func = event1, time = 1)
The above would call event1 at time=1. Is there a way to also call event2 at a different time?
I am relatively new to R so apologies if I am missing something obvious.
Many thanks,
Tom
More information about the R-sig-dynamic-models
mailing list