[R-sig-dyn-mod] How to find equilibrium conditions for simObjs (simecol package)

Thomas Petzoldt thomas.petzoldt at tu-dresden.de
Wed Oct 5 11:03:31 CEST 2016


Hi,

the solver can be changed by assigning an existing or an own solver 
function to the solver slot with:

solver(mySimObj) <- function(y, times, func, parms,  ...)

see example below.

Thomas


library("simecol")

logist <- new(
   "odeModel",
   main = function (t, N, p) {
     dN <- p["r"] * N * (1 - N / p["K"])
     list(c(dN))
   },
   parms  = c(r = 0.2, K = 100),
   times  = seq(0, 200, by = 1),
   init   = c(N = 1),
   solver="lsoda"
)

## dynamic simulation
logist <- sim(logist)
plot(logist)

## equilibrium with rootSolve
library("rootSolve")

## (1) simple approach:
## assign an existing solver from package rootSolve
solver(logist) <- "runsteady"
times(logist) <- c(0, Inf)
out(sim(logist))

## (2) write an own solver with more control,
## e.g. returning only the equilibrium state
mySolver <- function(y, times, func, parms, ...) {
    runsteady(y, times, func, parms,  ...)$y
}

solver(logist) <- "mySolver"

out(sim(logist))



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