Created
August 20, 2020 01:42
-
-
Save tmastny/8507052d17ec41d78b0abfc698536f1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: https://www.r-bloggers.com/lotka-volterra-model%C2%A0%C2%A0intro/ | |
library(deSolve) | |
LotVmod <- function (Time, State, Pars) { | |
with(as.list(c(State, Pars)), { | |
dx = x * (alpha - beta * y) | |
dy = -y * (gamma - delta * x) | |
return(list(c(dx, dy))) | |
}) | |
} | |
Pars <- c(alpha = 2, beta = .5, gamma = .2, delta = .6) | |
State <- c(x = 10, y = 10) | |
Time <- seq(0, 100, by = 1) | |
out <- as.data.frame(ode(func = LotVmod, y = State, parms = Pars, times = Time)) | |
matplot(out[,-1], type = "l", xlab = "time", ylab = "population") | |
legend( | |
"topright", | |
c("Cute bunnies", "Rabid foxes"), | |
lty = c(1,2), col = c(1,2), box.lwd = 0 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment