[R] lsoda with arbitrary zero thresholds
Martin Henry H. Stevens
HStevens at MUOhio.edu
Wed Jun 9 18:45:04 CEST 2004
using R 2.0.0
I am trying to do some population modeling with lsoda, where I set
arbitrary zero population sizes when values get close to zero, but am
having no luck.
As an example of what I have tried, I use code below from the help page
on lsoda in which I include my modification bordered by ###
parms <- c(k1=0.04, k2=1e4, k3=3e7)
my.atol <- c(1e-6, 1e-10, 1e-6)
times <- seq(0,)
lsexamp <- function(t, y, p)
{ ### The next line is where I try to insert the threshold
ifelse(y < 0.4, 0, y)
###### all else is unchanged
yd1 <- -p["k1"] * y[1] + p["k2"] * y[2]*y[3]
yd3 <- p["k3"] * y[2]^2
list(c(yd1,-yd1-yd3,yd3),c(massbalance=sum(y)))
}
out <- lsoda(c(.5,0,.5),times,lsexamp, parms, rtol=1e-4, atol= my.atol)
# Initial values differ from help page
matplot(out[,1],out[,2:5], type="l")
out[dim(out)[1],] # The intent of my could was to cause population 1 to
fall to zero as soon as it reached < 0.4
Any thoughts would be appreciated. Thanks!
Hank Stevens
Dr. Martin Henry H. Stevens, Assistant Professor
338 Pearson Hall
Botany Department
Miami University
Oxford, OH 45056
Office: (513) 529-4206
Lab: (513) 529-4262
FAX: (513) 529-4243
http://www.cas.muohio.edu/botany/bot/henry.html
http://www.muohio.edu/ecology/
http://www.muohio.edu/botany/
"E Pluribus Unum"
More information about the R-help
mailing list