Skip to contents

substitute_vars(x, rules) replaces subexpressions of x as given by rules (formulas x ~ 2, pairs list(x, 2), or a named list), in one top down pass. x may be an expression, an equation, a list, or a System, in which case equations, unknowns, parameters, variable maps, observed equations, costs, constraints and subsystems are substituted, as substitute(sys, rules) in ModelingToolkit. With a named list of systems, the subsystems of those names are replaced. This is ModelingToolkit's substitute, renamed so that base::substitute is not masked.

Usage

substitute_vars(x, rules)

Arguments

x

An expression, equation, list or System.

rules

The substitutions.

Value

The substituted object.

Examples

t <- t_nounits; D <- D_nounits
x <- Variable("x", t); k <- Parameter("k")
substitute_vars(-k * x, list(k ~ 2))
#> -2*x(t)