# NOT RUN {
## (1) Quick Start Examples ====================================================
data(lv) # load basic Lotka-Volterra model
# }
# NOT RUN {
require("tcltk")
lv <- editParms(lv)
# }
# NOT RUN {
parms(lv)
main(lv)
lv <- sim(lv)
plot(lv)
results <- out(lv)
# }
# NOT RUN {
data(conway) # Conway's game of life
init(conway) <- matrix(0, 10, 10)
times(conway) <- 1:100
conway <- editInit(conway) # enter some "1"
sim(conway, animate=TRUE, delay=100)
# }
# NOT RUN {
## (2) Define and run your own simecol model ==========================
lv <- new("odeModel",
main = function (time, init, parms) {
with(as.list(c(init, parms)), {
dn1 <- k1 * N1 - k2 * N1 * N2
dn2 <- - k3 * N2 + k2 * N1 * N2
list(c(dn1, dn2))
})
},
parms = c(k1 = 0.2, k2 = 0.2, k3 = 0.2),
times = c(from = 0, to = 100, by = 0.5),
init = c(N1 = 0.5, N2 = 1),
solver = "lsoda"
)
lv <- sim(lv)
plot(lv)
## (3) The same in matrix notation; this allows generalization ====
## to multi-species interaction models with > 2 species. ====
LVPP <- new("odeModel",
main = function(t, n, parms) {
with(parms, {
dn <- r * n + n * (A %*% n)
list(c(dn))
})
},
parms = list(
# growth/death rates
r = c(k1 = 0.2, k3 = -0.2),
# interaction matrix
A = matrix(c(0.0, -0.2,
0.2, 0.0),
nrow = 2, ncol = 2, byrow=TRUE)
),
times = c(from = 0, to = 100, by = 0.5),
init = c(N1 = 0.5, N2 = 1),
solver = "lsoda"
)
plot(sim(LVPP))
# }
Run the code above in your browser using DataLab