[R-sig-dyn-mod] Question About solving ODE with help of deSolve
Thomas Petzoldt
Thomas.Petzoldt at tu-dresden.de
Thu Jun 19 18:05:11 CEST 2014
Dear Munjal Patel,
this mailing does not support attachments, i.e. no Word, PDF, ... Please
include your material as plain text (preferred) or put supporting
material to a web server and link to it.
However, if I understand your "changing variable" correctly, it can be
implemented as a forcing function, see
?forcings
or the minimal example below.
Thomas
library("deSolve")
mod <- function(t, y, p) {
a <- p[1]
b <- signal(t)
dy <- a + b * y[1]
list(c(dy), a, b=b)
}
times <- seq(0, 4, 0.5)
Cp <- c(0.00E+00, 6.19E-01, 8.53E-01, 8.84E-01, 8.15E-01, 7.06E-01,
5.89E-01, 4.78E-01, 3.80E-01)
signal <- approxfun(times, Cp, rule=2)
p <- c(a=.1)
y0 <- c(y=1)
out <- ode(y0, times, mod, p)
plot(out)
out
More information about the R-sig-dynamic-models
mailing list