[R-sig-dyn-mod] Event value based on the state of the system at the time the event occurs
Daniel Kaschek
daniel.kaschek at physik.uni-freiburg.de
Sun Oct 18 20:38:40 CEST 2015
Hi John,
you might have a look at help(events), example 2. I think, you need an
event function. Within the event function you can access all states a
the current time point of integration.
Cheers,
Daniel
On So, 2015-10-18 at 11:23 -0700, John Harrold wrote:
> Howdy Folks,
>
> I've run into a situation where I need to create events where the values
> are dependent on one of the current state values. To give you an example,
> consider the system described below.
>
> the values (c(4,4)) actually need to be c(4*var[2], 4*var[2]), where var[2]
> is the value of the state var[2] at times 1 and 6, respectively. I don't
> know if what I want to do is possible using the event framework. I may have
> to write a wrapper that integrates from one event to the next and restarts
> the system (this is what I've done in Matlab), but I wanted to see if there
> was some kind of callback routine that I might be able to use so I can
> stick with the framework deSolve provides.
>
> Thanks
> John
>
>
> derivs <- function(t, var, parms) {
> list(c(-var[1]*parms[1], var[2]*(1-var[2]/parms[2])))
> }
>
> yini <- c(v1 = 0, v2=1)
> times <- seq(0, 10, by = 0.1)
>
> eventdat <- data.frame(var = c("v1", "v1"),
> time = c(1, 6) ,
> value = c(4, 4),
> method = c("add", "mult", "rep", "add"))
>
> eventdat
> parms = c(0.1, 10)
> out <- vode(func = derivs,
> y = yini,
> times = times,
> parms = parms,
> events = list(data = eventdat))
> plot(out)
>
>
More information about the R-sig-dynamic-models
mailing list