[R-sig-dyn-mod] Limiting State Value to remain below a maximum value

Thomas Petzoldt thomas.petzoldt at tu-dresden.de
Tue Jul 28 23:06:31 CEST 2015


Hi,

in agreement with David I would prefer "repulsive" terms. This may also 
have some mechanistic interpretation here, e.g. a "moisture" dependent 
loss-term.

In other cases, limitations occur naturally as consequence of having 
explicit equations for resources (R=2 in example m2).

ThomasP


library(deSolve)

m1 <- function(t, y, p) {
   with(p, {
     f <- k / (ymax - y)
     dy <- a - f
     list(dy, f=f)
   })
}

o1 <- ode(c(y=0), seq(0, 20, length.out=100), m1,
           list(a=0.2, ymax=2, k=1e-3))
plot(o1)

## "resource R" dependent

m2 <- function(t, y, p) {
   with(p, {
     f  <- y[2] / (k + y[2])
     dy <-   a * f   # state
     dR <- - a * f   # resource
     list(c(dy, dR))
   })
}

o2 <- ode(c(y=0, R=2), seq(0, 20, length.out=100), m2,
           list(a=0.2, k=1e-3))
plot(o2)

## note the small difference between the approaches ;-)
plot(o1[,c("time", "y")], type="l")
lines(o2[,c("time", "y")], lty="dashed", col="green")



More information about the R-sig-dynamic-models mailing list