# The Aphid model from Soetaert and Herman, 2008.
# A practical guide to ecological modelling.
# Using R as a simulation platform. Springer.
# 1-D diffusion model
#==================#
# Model equations #
#==================#
Aphid <-function(t,APHIDS,parameters)
{
deltax <- c (0.5,rep(1,numboxes-1),0.5)
Flux <- -D*diff(c(0,APHIDS,0))/deltax
dAPHIDS <- -diff(Flux)/delx + APHIDS*r
# the output
list(dAPHIDS )
} # end of model
#==================#
# Model application#
#==================#
# the model parameters: #
D <- 0.3 # m2/day diffusion rate
r <- 0.01 # /day net growth rate
delx <- 1 # m thickness of boxes
numboxes <- 60
# distance of boxes on plant, m, 1 m intervals
Distance <- seq(from=0.5,by=delx,length.out=numboxes)
# Initial conditions: # ind/m2
# aphids present only on two central boxes
APHIDS <- rep(0,times=numboxes)
APHIDS[30:31] <- 1
state <- c(APHIDS=APHIDS) # initialise state variables
# RUNNING the model: #
times <-seq(0,200,by=1) # output wanted at these time intervals
out <- ode.band(state,times,Aphid,parms=0,nspec=1)
#==================#
# Plotting output #
#==================#
# the data in 'out' consist of: 1st col times, 2-41: the density
# select the density data
DENSITY <- out[,2:(numboxes +1)]
filled.contour(x=times,y=Distance,DENSITY,color= topo.colors,
xlab="time, days", ylab= "Distance on plant, m",
main="Aphid density on a row of plants")
Run the code above in your browser using DataLab