inv (Matrix)

Tries to invert a square matrix. If the matrix is invertible, the function returns

I D _ TRUE
, where
I
is the adjugate and
D
is the determinant. If the inverse doesn't exist, the function returns
_ 0 c FALSE
, where c * M^T = <0> (zero vector).

Arguments

The square

matrix
to invert.

Return values

Resulting

adjugateMatrix
, empty if it doesn't exist (see Matrix).
determinant
of the matrix, as a real number.
eigenvector
of the matrix, empty if it doesn't exist (see Vector).
invertibleCondition
is TRUE if the matrix can be inverted, FALSE otherwise.

Complexity

O(size^3)

Example

"sl/algebra" useFile checkedInv: [ inv [ drop "det:" print print LF print m:; m.rows [i m.rowRange [print "," print] each LF print] times ] [ v:; drop drop "v:" print LF print v.makeRange [print "," print] each ] if ] func; ((2.0 1.0 1.0) (-1.0 1.0 1.0) (0.0 2.0 -2.0)) makeMatrix checkedInv ((2.0 1.0 1.0) (-5.0 1.0 2.0) (-1.0 0.666666 1.0)) makeMatrix checkedInv
Output:
det:-12.000000 -4.000000,4.000000,0.000000, -2.000000,-4.000000,-3.000000, -2.000000,-4.000000,3.000000, v: -0.111111,1.000000,-0.777778,