Just thinking here: I'm wondering whether
sir_equations <- function(time, variables, parameters) {
with(as.list(c(variables, parameters)), {
inc <- beta * (I1 + I2 + I3 + I4 + I5) * S
r1 <- gamma * I1
r2 <- gamma * I2
r3 <- gamma * I3
r4 <- gamma * I4
r5 <- gamma * I5
dS <- -inc
dI1 <- inc - r1
dI2 <- r1 - r2
dI3 <- r2 - r3
dI4 <- r3 - r4
dI5 <- r4 - r5
dR <- r5
list(c(dS, dI1, dI2, dI3, dI4, dI5, dR))
})
}
would be faster than
sir_equations <- function(time, variables, parameters) {
with(as.list(c(variables, parameters)), {
dS <- -beta * (I1 + I2 + I3 + I4 + I5) * S
dI1 <- (beta * (I1 + I2 + I3 + I4 + I5) * S) - (gamma * I1)
dI2 <- (gamma * I1) - (gamma * I2)
dI3 <- (gamma * I2) - (gamma * I3)
dI4 <- (gamma * I3) - (gamma * I4)
dI5 <- (gamma * I4) - (gamma * I5)
dR <- gamma * I5
list(c(dS, dI1, dI2, dI3, dI4, dI5, dR))
})
}
(7 multiplications instead of 14 and multiplications are time consuming). Maybe worth doing a little benchmarking here, at least out of curiosity?
Just thinking here: I'm wondering whether
would be faster than
(7 multiplications instead of 14 and multiplications are time consuming). Maybe worth doing a little benchmarking here, at least out of curiosity?