Skip to content

Instantly share code, notes, and snippets.

@CnrLwlss
Created October 22, 2016 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CnrLwlss/98808d7e5ba737397473e50e3ff4b52f to your computer and use it in GitHub Desktop.
Save CnrLwlss/98808d7e5ba737397473e50e3ff4b52f to your computer and use it in GitHub Desktop.
Simulating growth of a nutrient-limited population consisting of a mixture of two lineages with different growth rates (but sharing resources, i.e. co-localised).
# Install and load ODE solver package
#install.packages("deSolve")
library(deSolve)
# Named vector of parameter values
parameters=c(r_1=1.0,r_2=1.1,K=1)
# Named vector of initial conditions
state=c(x_1=0.01,x_2=0.01)
# Function describing ODEs
limited_mixed_pop=function(t,state,parameters){
with(as.list(c(state,parameters)),{
dx_1 <- r_1*x_1*(1-(x_1+x_2)/K)
dx_2 <- r_2*x_2*(1-(x_1+x_2)/K)
return(list(c(dx_1, dx_2)))
})
}
# Report concentrations at this vector of times
times=seq(0,20,by=0.01)
# Simulate from the model, given initial conditions and parameter values
out=ode(y=state,times=times,func=limited_mixed_pop,parms=parameters)
# Plot output
plot(out[,1],out[,2],type="l",ylim=c(0,max(out[,2:length(colnames(out))])),xlab="Time (d)",ylab="Cell density (AU)",lwd=3,cex.lab=1.5)
points(out[,1],out[,3],type="l",col="blue",lwd=3)
legend("bottomright",colnames(out)[2:length(colnames(out))],col=c("black","blue"),lwd=3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment