[R-sig-dyn-mod] ODE question
Soetaert, Karline
K.Soetaert at nioo.knaw.nl
Fri Jul 2 18:07:37 CEST 2010
Andrew,
I am not sure, but perhaps this is what you want?
SIR <- function(t, y, p) {
S <- y[1:100]
I <- y[101:200]
R <- y[201:300]
dS<- -0.1*I*S
dI <- 0.1*I*S - 0.15*I
dR <- 0.15*I
list(c(dS, dI, dR))
}
yini <- c(S=1:100, I = 2:101, R = rep(0,100))
out <- ode(y= yini, times=0:1000, p=0, func=SIR)
out2<- ode.1D(y= yini, times=0:1000, p=0, func=SIR, nspec=3)
The last solution method (ode.1D) is faster only if you have lots of "strata".
Karline
________________________________
From: r-sig-dynamic-models-bounces at r-project.org on behalf of Hill, Andrew N.
Sent: Fri 7/2/2010 6:25 AM
To: r-sig-dynamic-models at r-project.org
Subject: [R-sig-dyn-mod] ODE question
Hello,
I have a system of ODEs for an infectious disease model. It is a heterogeneous SEIR model, where each S, E, I, R type compartment has n strata. Depending on the situation, n is typically of the order of 10. My question is can I define the system of ODEs by some kind of vectorization and pass to deSolve to solve? Rather than type out the 10*4=40 differential equations, I would prefer to set it up as 4 vectorized diff eqs for each S, E, I, R. How do I do this in R and specify 4 initial conditions consisting of vectors of length 10 then solve it with deSolve?
I hope my question makes sense and thanks in advance.
Andrew
This e-mail message (including any attachments) is for t...{{dropped:11}}
_______________________________________________
R-sig-dynamic-models mailing list
R-sig-dynamic-models at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 5001 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-dynamic-models/attachments/20100702/1b5f9636/attachment.bin>
More information about the R-sig-dynamic-models
mailing list