Controls variables for ODESystem

Hi all,

I’m looking through the documentation on ODESystems in ModelingToolkit and came across the ctrls (control parameters) argument for ODESystems:

  • ctrls
    Control parameters (some subset of ps ).

This sounds like something I’m after, but I can’t seem to find any examples in the documentation of this argument being used explicitly.

My questions:

  1. Are there any existing examples of how to use control variables like this for ODESystems?
  2. Can these control variables be any external function? Something like that exists here, but I don’t know if this works here too
  3. Since these control variables are a subset of the parameters, can any parameter be selected as a control variable after the model is built, or do these need to be defined beforehand?


1 Like

The functionality attached to the ctrls field is not very well developed at the moment. You may have a look at the example that starts here by defining

@variables u(t) [input=true] 

followed by

f, dvs, ps = ModelingToolkit.generate_control_function(model, expression=Val{false}, simplify=true)

which generates a tuple of functions f where f[1] is a function on the form

ẋ = f(x, u, p, t)

where x is the state and u the control input. Note that this functionality is still quite limited and this is why it’s not yet fully documented.

For simulation of systems with control inputs using MTK, see this example