clogistic <- function(times, y, parms) {
n <- y[1]
r <- parms[1]
k <- parms[2]
dN.dt <- r * n * (1 - n /k)
return(list(c(dN.dt)))}
prms <- c(r = 1, k = 100)
init.N <- c(1)
t.s <- seq(0.1, 10, by = 0.1)
library(deSolve)
out <- ode(y = init.N, times = t.s, clogistic, parms = prms)
plot(out[, 1], out[, 2], type = "l", xlab = "Time", ylab = "N")

##Podemos generar una serie de poblaciones aleatorias que varian en la tasa de crecimiento intrÃnseca y tienen la misma capacidad de carga
outmat <- matrix(NA, nrow = length(t.s), ncol = 20)
for (j in 1:20) outmat[, j] <- {y <- runif(n = 1, min = 0, max = 120)
prms <- c(r = runif(1, 0.01, 2), k = 100)
ode(y, times = t.s, clogistic, prms)[, 2]}
matplot(t.s, outmat, type = "l", col = 1, ylab = "All Populations")
