Skip to contents

NonlinearProblem(sys, op) builds the root finding problem f(u, p) = 0 from a complete time independent system: the unknowns u start from the values in op (formulas x ~ 1, pairs, or a named list), the initial conditions of the system, and its guesses, in that order. NonlinearLeastSquaresProblem() is the same for systems with more equations than unknowns, solved in the least squares sense. NonlinearFunction(sys) builds the residual and, with jac = TRUE, the symbolic Jacobian. A time dependent system is first turned into its steady state system (derivatives set to zero).

Usage

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

NonlinearProblem(
  sys,
  op = list(),
  ...,
  jac = TRUE,
  u0 = NULL,
  p = NULL,
  lb = NULL,
  ub = NULL,
  guesses = list(),
  missing_guess_value = NULL,
  check_length = TRUE
)

NonlinearLeastSquaresProblem(
  sys,
  op = list(),
  ...,
  jac = TRUE,
  u0 = NULL,
  p = NULL,
  lb = NULL,
  ub = NULL,
  guesses = list(),
  missing_guess_value = NULL,
  check_length = FALSE
)

Arguments

sys

A complete System, an R function f(u, p), or a NonlinearFunction.

jac

Generate the symbolic Jacobian. Without it solvers use finite differences.

...

Solver options stored with the problem (abstol, maxiters, ...).

op

Operating point: values of unknowns and parameters.

u0, p

Initial values and parameters for raw problems.

lb, ub

Lower and upper bounds of the unknowns.

guesses

Further guesses, as a variable map.

missing_guess_value

What to do with unknowns that have no value and no guess; see MissingGuessValue.

check_length

Require as many equations as unknowns.

Value

A NonlinearFunction, NonlinearProblem or NonlinearLeastSquaresProblem.

Details

NonlinearProblem(f, u0, p) with an R function f(u, p) builds a problem without a system.

Bounds are taken from the bounds metadata of the unknowns unless lb or ub is given; iterates are projected onto the box.

Examples

x <- Variable("x"); y <- Variable("y"); a <- Parameter("a")
sys <- complete(System(list(0 ~ x^2 + y^2 - a, 0 ~ x - y), name = "ns"))
prob <- NonlinearProblem(sys, list(x ~ 1, y ~ 2, a ~ 2))
sol <- solve(prob)
sol$u
#> x y 
#> 1 1 
sol[x + y]
#> [1] 2
# without a system
sol2 <- solve(NonlinearProblem(function(u, p) u^2 - p, 1, 2))
sol2$u
#> [1] 1.414214