Parameter substitutions in ModelingToolkit.jl


I’m getting to grips with ModelingToolkit.jl. Let’s take the ODE building example in the tutorial:

@parameters t σ ρ β
@variables x(t) y(t) z(t)
@derivatives D'~t

eqs = [D(x) ~ σ*(y-x),
       D(y) ~ x*(ρ-z)-y,
       D(z) ~ x*y - β*z]

First question: can I substitute the parameters in eqs with fixed constants? I couldn’t figure out how to do this.

The reason I’m asking this quesiton:
Suppose I have some fixed, nominal values for the tree parameters. I want to build a 7 state ODEProblem whose vector field looks like:

[eqs with fixed parameter values;
eqs with free parameter values;
l2 difference of the two eqs]

When I solve such a system, the final state vector at time t will give me the integral (over time) of the L2 difference between the Lorenz system with fixed parameter values, and with free parameter values. In particular, I’m hoping that the fixed parameter values enter the ODEProblem just as constants, so that there are only three free parameters in the ODEProblem

The question is, how do I substitute fixed parameter values into my array eqs? Or is there another way to generate an ODEFunction of the form I want?

I want to do this so I can efficiently take automatic derivatives of the L2 difference between the fixed=parameter and variable=parameter solutions, as a function of the variable parameters. This is equivalent to solving the adjoint sensitivity problem, where the cost functional depends on both the fixed-parameter and variable-parameter solutions.

Thanks in advance!

1 Like

More simply: given an equation with some variables, how do I substitute a different set of variables/constants in the equation?

We don’t have a function for that yet… @shashi have you thought of a way to implement it?