Skip to contents

ImplicitDiscreteProblem(sys, op, tspan) builds the implicit map f(u_next, u, p, t) = 0 of a compiled discrete system with algebraic equations, as ModelingToolkit's ImplicitDiscreteProblem: equations Shift(x, 1) ~ rhs give rhs - x_next and algebraic equations 0 ~ g are evaluated at the next step. ImplicitDiscreteFunction(sys) builds f. ImplicitDiscreteProblem(f, u0, tspan, p) takes an R function f(u_next, u, p, t). Solve with IDSolve(), which steps by dt (default 1) and solves each step with Newton's method; the initial state is made consistent by one solve at the initial time.

Usage

ImplicitDiscreteFunction(sys, ...)

ImplicitDiscreteProblem(
  sys,
  op = list(),
  tspan = NULL,
  ...,
  u0 = NULL,
  p = NULL
)

IDSolve()

Arguments

sys

A compiled discrete System, or an R function.

...

Solver options stored with the problem.

op

Values of (past) unknowns and parameters.

tspan

Time span.

u0, p

Initial state and parameters of raw problems.

Value

An ImplicitDiscreteProblem, ImplicitDiscreteFunction, or algorithm object.

Examples

# u_next solves u_next + u_next^3 = u
f <- function(un, u, p, t) un + un^3 - u
prob <- ImplicitDiscreteProblem(f, 2, c(0, 3))
sol <- solve(prob, IDSolve())
sol$u
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 0.6823278
#> 
#> [[3]]
#> [1] 0.5318697
#> 
#> [[4]]
#> [1] 0.4442144
#>