[R-sig-dyn-mod] Event value based on the state of the system at the time the event occurs

John Harrold john.m.harrold at gmail.com
Sun Oct 18 20:23:42 CEST 2015


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)


-- 
-------------------------------------
John M. Harrold
john.m.harrold _at_gmail
-------------------------------------

	[[alternative HTML version deleted]]



More information about the R-sig-dynamic-models mailing list