JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://symbolics.juliasymbolics.org/stable/
Other
1.34k stars 150 forks source link

Symbolic matrix inverse via Adjugate matrix #864

Open Gregstrq opened 1 year ago

Gregstrq commented 1 year ago

May it makes sense to rewrite matrix inverse and left division using the direct expression for the inverse matrix using the adjugate matrix?

Right now computation of the inverse matrix results in incomprehensible expressions. Via the adjugate matrix you explicitly get the matrix elements in the form matrix element of adjugate matrix/determinant, that could be more readable.

Another problem right now is that the computation of the inverse matrix results in the appearance of Bool true terms. It can be understood in the following manner: the inverse is computed by left division of identity matrix, which is generated via

Matrix{Num}(I, n,n)

The diagonal matrix elements are Num(true), which is not the same as Num(1). Bool variables does not make any sense in the context of symbolic computations to my taste.

You can see both problems with true terms and incomprehensible expressions using the following example:

using Symbolics
@variables Ω ω₀ Δ
M = [-ω₀ 2Ω 0; -2Ω -ω₀ 2Δ; 0 -2Δ -ω]
inv(M)
ChrisRackauckas commented 1 year ago

Seems like a reasonable approach.

Gregstrq commented 1 year ago

The only downside that it would be quite slow for large matrices. On the other hand, I can not imagine working with huge matrices in the context of symbolic computation.

Anyway, we can add a keyword argument akin to laplace keyword argument of det function, to choose between the two algorithms.