Goal. I want to linearize a plant at a steady-state operating point that is specified by output targets. The inputs that hold the outputs at those targets are to be solved for by the initialization, as SciML/ModelingToolkit.jl#4830 made possible with u => missing in op.
What I tried. The steady-state condition D(x) => 0, the target y => 4, the input u => missing with a guess, and x => nothing to remove the initial condition of the state:
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
@variables x(t) = 1.0 u(t) [input = true] y(t) [output = true]
@named sys = System([D(x) ~ -x + u^2, y ~ x], t)
op = Dict(y => 4.0, D(x) => 0.0, u => missing, x => nothing)
mats, ssys, extras = ModelingToolkit.linearize(sys, [u], [y]; op, guesses = Dict(u => 1.0, x => 1.0))
How it fails. The initialization finds the operating point: extras.x == [4.0], and extras.p holds the solved input u = 2.0. The input matrix, however, is the Jacobian at the guess of the input rather than at the solved value:
julia> mats.A
1×1 Matrix{Float64}:
-1.0
julia> mats.B
1×1 Matrix{Float64}:
2.0
At the operating point, ∂(-x + u²)/∂u = 2u = 4; the value 2 is 2u at the guess u = 1. The state Jacobian is correct.
In src/linearization.jl, the call method of LinearizationFunction reads the input values (linfun.inputs_getter(linfun.prob)) before SciMLBase.get_initial_values, and passes these values to pf_jac and hp_jac. The code on master reads them at the same point. I have not run the example on master.
Is there an intended way to obtain the linearization at the inputs the initialization solves for? A single linearize call at such an operating point is what I would like to use.
Versions: ModelingToolkit 11.43.1, ModelingToolkitBase 1.73.0, Julia 1.12.7.
Goal. I want to linearize a plant at a steady-state operating point that is specified by output targets. The inputs that hold the outputs at those targets are to be solved for by the initialization, as SciML/ModelingToolkit.jl#4830 made possible with
u => missinginop.What I tried. The steady-state condition
D(x) => 0, the targety => 4, the inputu => missingwith a guess, andx => nothingto remove the initial condition of the state:How it fails. The initialization finds the operating point:
extras.x == [4.0], andextras.pholds the solved inputu = 2.0. The input matrix, however, is the Jacobian at the guess of the input rather than at the solved value:At the operating point,
∂(-x + u²)/∂u = 2u = 4; the value 2 is2uat the guessu = 1. The state Jacobian is correct.In
src/linearization.jl, the call method ofLinearizationFunctionreads the input values (linfun.inputs_getter(linfun.prob)) beforeSciMLBase.get_initial_values, and passes these values topf_jacandhp_jac. The code on master reads them at the same point. I have not run the example on master.Is there an intended way to obtain the linearization at the inputs the initialization solves for? A single
linearizecall at such an operating point is what I would like to use.Versions: ModelingToolkit 11.43.1, ModelingToolkitBase 1.73.0, Julia 1.12.7.