Skip to contents

Variable() declares one unknown, Parameter() one parameter and Constant() one constant, each with optional metadata. They correspond to the @variables, @parameters and @constants macros of ModelingToolkit: Variable("x", t, default = 1) is @variables x(t) = 1 and Parameter("k", default = 0.5) is @parameters k = 0.5.

Usage

Variable(
  name,
  iv = NULL,
  default = NULL,
  guess = NULL,
  bounds = NULL,
  description = NULL,
  input = NULL,
  output = NULL,
  irreducible = NULL,
  state_priority = NULL,
  connect = NULL,
  unit = NULL,
  disturbance = NULL,
  tunable = NULL,
  dims = NULL,
  ...
)

Parameter(
  name,
  iv = NULL,
  default = NULL,
  guess = NULL,
  bounds = NULL,
  description = NULL,
  tunable = NULL,
  unit = NULL,
  dims = NULL,
  ...
)

Constant(name, default, description = NULL, unit = NULL)

Brownian(name, description = NULL)

Poissonian(name, rate, description = NULL)

Discrete(name, iv, default = NULL, description = NULL, ...)

Arguments

name

The name, a string.

iv

The independent variable, or a list of independent variables, for dependent variables such as x(t) or u(t, x). NULL declares a time independent variable.

default

Default value: a number, a symbolic expression or NA.

guess

Initial guess used by initialization.

bounds

Numeric vector c(lower, upper).

description

A string.

input, output

Mark the variable as a system input or output.

irreducible

Keep the variable as an unknown during mtkcompile().

state_priority

Number; higher values are preferred as states.

connect

Connector type for connector variables: "Flow", "Stream" or "Equality".

unit

A unit, as a string.

disturbance

Mark as a disturbance input.

tunable

For parameters: whether the parameter is tunable (default TRUE).

dims

Array dimensions, for array variables.

...

Further metadata: dist, nominal, misc, scope, binary, integer.

rate

The rate of a Poisson counting process.

Value

A sym expression carrying its metadata, or a list for arrays.

Details

A default that is a number becomes an initial condition of any system the variable is used in. A default that is a symbolic expression, or NA (Julia's missing), becomes a binding: the variable is then determined by that expression, or solved for during initialization.

With dims, an array of scalar variables named x[1], x[2], ... is returned as a list.

See also

variables() declares several variables from strings.

Examples

t <- t_nounits
x <- Variable("x", t, default = 1, description = "position")
k <- Parameter("k", default = 0.5)
getdefault(x)
#> [1] 1
getdescription(x)
#> [1] "position"