ntimes = 50
H = numeric(ntimes) # Host
P = numeric(ntimes) # Parasitoid
H = .4; P = 2.0 # initial values for populations H and P
for (i in 2:ntimes) {
H[i+1] = (8.7*H[i]*exp^(-0.4*P[i]))/(1+(4.7*H[i]))
P[i+1] = (5.5*H[i])*(1-exp^(-0.4*P[i]))
}
Error in exp^(-0.4 * P[i]) : non-numeric argument to binary operator The model equation I am tryinng to create 
Cannot figure out why I am getting this Error. This is a model adaptation from the Nicholson Bailey model. This is the initial code I used, Nicholson Bailey model.
ntimes = 25
H = numeric(ntimes) # Host
P = numeric(ntimes) # Parasitoid
H = 350; P = 150 # initial values for populations H and P
a = .004; c = 1; r = 1.75 # the parameter values
for (i in 2:ntimes) {
H[i] = r * H[i-1] * exp(-a * P[i-1])
P[i] = c * H[i-1] * (1 - exp(-a * P[i-1]))
}
par(mfrow = c(1,2)) # 1 x 2 graphics window
plot(1:ntimes, H, type = "n", las = 1,
xlim = c(0,25), ylim = c(0,1100),
ylab = "Number of Individuals",
xlab = "Time",cex.lab = 1.5)
leg.txt = c("Host","Parasitoid")
legend("topright",leg.txt,lwd=2,lty = c(1,2))
lines(1:ntimes,H,lwd=2,lty=1)
lines(1:ntimes,P,lwd=2, lty=2)
plot(H, P, las = 2,
xlim = c(0,800), ylim = c(0,1100),
ylab = "Number of Parasitoids", xlab = "Number of Hosts",
cex.lab = 1.5,type = "l",lwd = 2)
exp^(-0.4*P[i]))
toexp(-0.4*P[i]))
exp is a function in r, not a variable. you have it right in the initial code – jeremycgfor (i in 2:ntimes)
to befor (i in 1:ntimes)
– jeremycgH =.4; P = 2.0
butH[1]=.4;P[1]=2.0
; you are initializing the first elements (I presume). – Bhas