Learn R Programming

deTestSet (version 1.0)

dae: General Solver for Differential Algebraic Equations

Description

Solves a system of differential algebraic equations; a wrapper around the implemented DAE solvers

Usage

dae(y, times, parms, dy, res = NULL, func = NULL,
    method = c("mebdfi", "daspk", "radau", "gamd", "bimd"), ...)

Arguments

y
the initial (state) values for the DAE system, a vector. If y has a name attribute, the names will be used to label the output matrix.
times
time sequence for which output is wanted; the first value of times must be the initial time.
parms
vector or list of parameters used in res
dy
the initial derivatives of the state variables of the DAE system.
func
to be used if the model is an ODE, or a DAE written in linearly implicit form (M y' = f(t, y)). func should be an R-function that computes the values of the derivatives in the ODE system (the model definition) at tim
res
either an R-function that computes the residual function F(t,y,y') of the DAE system (the model defininition) at time t, or a character string giving the name of a compiled function in a dynamically loaded shared library.
method
the solver to use, either a string ("mebdfi", "daspk"), "radau", "gamd" or a function that performs integration.
...
additional arguments passed to the solvers.

Value

  • A matrix of class deSolve with up to as many rows as elements in times and as many columns as elements in y plus the number of "global" values returned in the second element of the return from res, plus an additional column (the first) for the time value. There will be one row for each element in times unless the integrator returns with an unrecoverable error. If y has a names attribute, it will be used to label the columns of the output value.

Details

This is simply a wrapper around the various dae solvers. See package vignette for information about specifying the model in compiled code. See the selected integrator for the additional options.

See Also

diagnostics to print diagnostic messages.

Examples

Run this code
## =======================================================================
## Chemical problem
## =======================================================================

daefun <- function(t, y, dy, parms) {
  with (as.list(c(y, dy, parms)), {
    res1 <- dA + dAB + lambda * A
    res2 <- dAB + dB
    alg <- B * A - K * AB
  list(c(res1, res2, alg), sumA = A + AB)
  })
}

parms <- c(lambda = 0.1, K = 1e-4)

yini  <- with(as.list(parms),
     c(A = 1, AB = 1, B = K))
dyini <- c(dA = 0, dAB = 0, dB = 0)

times <- 0:100

print(system.time(
out <-dae (y=yini, dy = dyini, times = times, res = daefun,
           parms = parms, method = "daspk")
))

plot(out, ylab = "conc.", xlab = "time", lwd = 2)
mtext("IVP DAE", side = 3, outer = TRUE, line = -1)

Run the code above in your browser using DataLab