substitute_component(sys, old, new) returns sys with the subsystem
old (obtained as sys$name, or sys$outer$name for a nested one)
replaced by new, as substitute_component(sys, old => new) in
ModelingToolkit. new must have the same name as the component it
replaces and offer all of its unknowns, parameters and subsystems, with
the same connector types and input or output markings, so that every
connection to the component stays valid.
Examples
t <- t_nounits; D <- D_nounits
x <- Variable("x", t); k <- Parameter("k")
decay <- System(list(D(x) ~ -k * x), t, name = "part")
growth <- System(list(D(x) ~ k * x), t, name = "part")
model <- System(list(), t, systems = list(decay), name = "model")
equations(substitute_component(model, model$part, growth))
#> [[1]]
#> Derivative(part₊x(t), t) ~ part₊k*part₊x(t)
#>