Skip to contents

DAEProblem(sys, op, tspan) builds a fully implicit differential algebraic problem F(du, u, p, t) = 0 from a complete system, as ModelingToolkit's DAEProblem: the residual of each equation is rhs - lhs, op gives initial values of unknowns, parameters and derivatives (D(x) ~ 0.5), and differential_vars marks the unknowns whose derivatives appear. DAEFunction(sys) builds the residual and, with jac = TRUE, the Jacobian dF/du + gamma * dF/d(du) as a function of (du, u, p, gamma, t).

Usage

DAEFunction(sys, jac = FALSE, ...)

DAEProblem(
  sys,
  op = list(),
  tspan = NULL,
  ...,
  jac = FALSE,
  du0 = NULL,
  u0 = NULL,
  p = NULL,
  differential_vars = NULL
)

generate_dae_jacobian(sys, ...)

Arguments

sys

A complete System, or an R function f(du, u, p, t).

jac

Generate the symbolic Jacobian (for a system); for an R residual function, the Jacobian jac(du, u, p, gamma, t) = dF/du + gamma * dF/d(du) (also accepted as jac_fn).

...

Solver options stored with the problem.

op

Operating point.

tspan

Time span.

du0, u0, p

Initial derivatives, initial values and parameters of raw problems.

differential_vars

Logical vector marking differential variables.

Value

A DAEProblem or DAEFunction.

Details

DAEProblem(f, du0, u0, tspan, p) with an R function f(du, u, p, t) builds a problem without a system. Solve with DFBDF() (the default) or DImplicitEuler(); the result is a DAESolution with the same interface as an ODE solution.

Examples

t <- t_nounits; D <- D_nounits
x <- Variable("x", t); y <- Variable("y", t)
sys <- mtkcompile(System(list(D(x) ~ -x + y, y ~ 2 * sin(t)), t, name = "dae"))
prob <- DAEProblem(sys, list(x ~ 1, D(x) ~ -1), c(0, 1))
sol <- solve(prob, DFBDF())
sol[x][length(sol$t)]
#> [1] 1.03693