Skip to contents

generate_control_function(sys, inputs) compiles sys with inputs as inputs and returns its dynamics as an R function f(x, u, p, t) (or f(x, u, p, t, w) with known disturbances), where x are the unknowns dvs, u the inputs and p the parameters ps. Unknown disturbance_inputs keep their dynamics but are set to zero. With implicit_dae = TRUE the function is the residual f(dx, x, u, p, t). inputs may also be analysis points, whose connections are opened.

Usage

generate_control_function(
  sys,
  inputs = NULL,
  disturbance_inputs = NULL,
  known_disturbance_inputs = NULL,
  implicit_dae = FALSE,
  simplify = FALSE,
  system_modifier = identity,
  ...
)

calculate_control_jacobian(sys, sparse = FALSE, simplify = FALSE)

generate_control_jacobian(sys, simplify = FALSE, sparse = FALSE, ...)

Arguments

sys

A System.

inputs

Input variables or analysis points.

disturbance_inputs

Unknown disturbance inputs.

known_disturbance_inputs

Disturbance inputs passed as w.

implicit_dae

Generate a residual function.

simplify

Passed to mtkcompile().

system_modifier

For analysis point inputs, a function applied to the opened system.

...

Unused.

sparse

Unused.

Value

A list with f, dvs, ps and the compiled system io_sys; for the Jacobian functions a symbolic matrix or an R function.

Details

calculate_control_jacobian(sys) is the Jacobian of the right-hand sides of sys with respect to its inputs and generate_control_jacobian(sys) compiles it to a function of (u, p, t).

Examples

t <- t_nounits; D <- D_nounits
x <- Variable("x", t); u <- Variable("u", t, input = TRUE)
k <- Parameter("k")
sys <- System(list(D(x) ~ -k * (x + u)), t, name = "s")
cf <- generate_control_function(sys, list(u))
cf$f(1, 3, 2, 0)
#> [1] -8