Symbolics.jl
Symbolics.jl copied to clipboard
Symbolic inverses
I saw an issue raised in early May that Symbolics no longer handles inv
of 1x1 matrices, e.g., [x;;]
where x
is a variable.
- This is still the case -- my linearization code doesn't work any more... :-o ---
Symbolics v5.5.0
I changed the code to T*A/T
(it is a similarity transform), and this works when T
is a 1x1 matrix.
HOWEVER, for some larger matrices (e.g., 2x2), the syntax T*A/T
may or may not work. Seems like the problem is resolved if I rewrite the expression as T*A*(I/T)
... weird. NOTE: for simple matrix products, T*A/T
works, while for more complex matrices (A,T), this may not work. BUT T*A*inv(T)
works for all cases I have tested.... except for scalars.
I'll come back with an example -- my laptop is running out of juice.
OK... Here are two matrices, AAA
and TTT
:
AAA = Num[(-K_e*u(t)) / (2A*h_ς*ρ*sqrt(h(t) / h_ς)) 0.0; (2.0K_e*m(t)*p(t)*u(t) + 4.0h_ς*ρ*Q̇_(t)*m(t)*sqrt(h(t) / h_ς) + 4.0A*h_ς*(ρ^2)*Ĥ(t)*ṁ_e(t)*sqrt(h(t) / h_ς) + 4.0g*h_ς*ρ*m(t)*ṁ_e(t)*sqrt(h(t) / h_ς) - 2.0K_e*ρ*m(t)*u(t)*Ĥ(t) - 4.0A*h_ς*ρ*p(t)*ṁ_e(t)*sqrt(h(t) / h_ς) - 4.0g*h_ς*ρ*m(t)*ṁ_i(t)*sqrt(h(t) / h_ς) - 4.0g*h_ς*(ρ^2)*V(t)*ṁ_e(t)*sqrt(h(t) / h_ς)) / (4A*h_ς*(ρ^2)*m(t)*sqrt(h(t) / h_ς)) (-ṁ_e(t)) / m(t)]
TTT = Num[1 / (A*ρ) 0.0; (A*p(t) + g*ρ*V(t) - g*m(t) - A*ρ*Ĥ(t)) / (A*ĉ_p*ρ*m(t)) -1 / (-ĉ_p*m(t))]
Doing similarity transformation:
TTT*AAA/TTT
leads to:
while:
TTT*AAA*(I/TTT)
leads to the correct result:
or... if I simplify
the elements:
In case it is useful... here are some parameters and variables:
@parameters ρ=1e3 A=1.5e-2 K_e=2 h_ς=3e-1 Ĥ_o=0 ĉ_p=4.2e3 T_o=298.15 p_o=1.01e5 p_a=1.01e5 g=9.81
@variables t h(t)=1.5e-1 m(t)=ρ*h*A ṁ_i(t) ṁ_e(t) p(t)=1.01e5 T(t)=293.15
@variables Ĥ(t)=Ĥ_o + ĉ_p*(T - T_o) + (p - p_o)/ρ
@variables U(t)= m*Ĥ - p*m/ρ Ḣ_i(t) Ḣ_e(t) Ẇ_v(t) Q̇(t)
@variables V(t) u(t)
@variables Ĥ_i(t) T_i(t) Q̇_(t)
D = Differential(t)