DiscreteProblem(sys, op, tspan) builds the map u[k+1] = f(u[k], p, t[k]) of a compiled discrete system, whose unknowns are the past values
xₜ₋₁, xₜ₋₂, ... of its variables (see shift2term()). Initial
conditions give the past: (k - 1)(x) ~ 1 (or Shift(t, -1)(x) ~ 1)
sets xₜ₋₁ at the initial time. A value (or default) for x itself is
its value at the initial time, and the past values not given are solved
for to match it, from guesses, as ModelingToolkit's initialization
does. DiscreteFunction(sys) builds f. Solve with solve(prob, FunctionMap()), which steps by dt (default 1) and saves every step.
Arguments
- sys
A compiled discrete
System, or an R functionf(u, p, t).- ...
Solver options stored with the problem.
- op
Values of past unknowns and of parameters.
- tspan
Time span
c(t0, t1).- u0, p
Initial state and parameters for problems from functions.
- guesses
Guesses for past values solved from initial conditions.
Details
DiscreteProblem(f, u0, tspan, p) builds a problem from an R function
f(u, p, t) returning the next state.
Examples
t <- t_nounits
x <- Variable("x", t)
k <- ShiftIndex(t)
sys <- mtkcompile(System(list(x ~ 0.5 * (k - 1)(x)), t, name = "halving"))
prob <- DiscreteProblem(sys, list((k - 1)(x) ~ 1), c(0, 5))
sol <- solve(prob, FunctionMap())
sol[x]
#> [1] 0.500000 0.250000 0.125000 0.062500 0.031250 0.015625