Thanks for the link!
I got it to work, but, interestingly, not with named_ss(), though i suspect the issue is linearize() which is called by named_ss.
For reference, the DAE produced by mtk consists of 3 differential variables (position s, current i, velocity v) and 2 algebraic variables (force f, acceleration a).
The equations(sys) are:
Differential(t)(axis₊prismatic₊s(t)) ~ axis₊prismatic₊v(t)
Differential(t)(axis₊motor₊inductor₊i(t)) ~ axis₊motor₊inductor₊v(t) / axis₊motor₊inductor₊L
Differential(t)(axis₊prismatic₊v(t)) ~ axis₊friction₊flange_b₊sˍtt(t) # <- This is an algebraic state
0 ~ axis₊prismatic₊f(t) + axis₊trans₊flange_trans₊f(t)
0 ~ axis₊body_mov₊frame_a₊xˍtt(t) - axis₊body_mov₊r1ˍtt(t)
Using named_ss produced the same ss model as linearize with all 5 states.
Here is the A matrix produced by linearize:
5Ă—5 Matrix{Float64}:
0.0 0.0 1.0 0.0 0.0
-0.0 -20.0 -251.327 -0.0 -0.0
0.0 0.0 0.0 0.0 1.0
0.0 -24.5417 -308.4 0.0 0.0
0.0 -4.90835 -61.6801 0.0 0.0
Notice that the rows 2, 4, 5 (i, f, a) are all linearly dependent.
That feels like a problem?
I tried bypassing linearize by manually building the Descriptor System, using calculate_massmatrix and ForwardDiff.jacobian on the compiled ODEProblem.
# 1. Extract Mass Matrix (E) from the working ODEProblem
E = prob.f.mass_matrix
# 2. Compute A numerically using ForwardDiff on the ODE function
f_func = (u) -> (out=similar(u); prob.f(out, u, prob.p, t); out)
A_numeric = ForwardDiff.jacobian(f_func, prob.u0)
# 3. Convert manually
sys_dss = dss(A_numeric, E, B, C, D)
sys_final = dss2ss(sys_dss, fast=false)
The A matrix now looks like this:
5Ă—5 Matrix{Float64}:
0.0 0.0 1.0 0.0 0.0
-0.0 -20.0 -251.327 -0.0 -0.0
0.0 0.0 0.0 0.0 1.0
0.0 1.25664 0.0 -1.0 -0.120409
0.0 0.0 0.0 -0.2 1.0
sys_final now is the correct ss model with 3 states.
Am i missing something or does linearize actually fail to linearize my model correctly?