On page 276 of the R book, when I run the following code with R2.9.2
phmodel <-function(t, x, parms) {
v<-x[1]
n<-x[2]
with(as.list(parms),{
dv=r*v*(K-v)/K - b*v*n
dn=c*v*n – d*n
res<-c(dv,dn)
list(res)
})}
times <-seq(0, 500, length=501)
parms <-c(r=0.4, K=1000, b=0.02, c=0.01, d=0.3)
y<-xstart <-c(v=50, n=10)
output <-as.data.frame(rk4(xstart, times, phmodel, parms))
plot (output$time, output$v,ylim=c(0,60),type="n",ylab="abundance",xlab="time")
lines (output$time, output$v)
lines (output$time, output$n,lty=2)
I got the following error message:
Error: unexpected input in:
"dv=r*v*(K-v)/K - b*v*n
dn=c*v*n –"
> res<-c(dv,dn)
Error: object 'dv' not found
> list(res)
Error: object 'res' not found
Any help will be appreciated!