[R-sig-dyn-mod] Modeling dampened oscillator with random resets
Thomas Petzoldt
Thomas.Petzoldt at tu-dresden.de
Wed Jan 9 16:07:48 CET 2013
On 09.01.2013 15:33, Felix Schönbrodt wrote:
> Dear list,
>
> using deSolve (or another package): is it possible to model a
> dampened oscillator that is reset to new states at specific points?
Yes, this is possible, using the event mechanism:
library(deSolve)
osci <- function (t, states, parms) {
with(as.list(c(states, parms)), {
dx <- y
dy <- eta * x + zeta * y
list(c(dx, dy))
})
}
states <- c(x = 1, y = 0)
out <- ode(states, osci, times = 1:200,
parms = c(eta = -0.05, zeta = -0.02))
plot(out)
### see ?events for details
eventdat <- data.frame(var = "y", time = c(70, 120),
value = c(0.7, 1), method = "add")
out <- ode(states, osci, times = 1:200,
parms = c(eta = -0.05, zeta = -0.02),
events = list(data = eventdat))
plot(out, which = "y")
abline(v = eventdat$time, col = "red", lty = "dashed")
## Thomas P.
More information about the R-sig-dynamic-models
mailing list