solve (Matrix)

Solves a system of linear equations xM=b. If it is solvable,

M b solve
returns
x D _ TRUE
such that (1/D)*x is the solution. If the system is not solvable,
M b solve
returns
_ _ c FALSE
such that c*M^T = <0> and b c dot =/= 0

Arguments

Coefficient

matrix
(see Matrix).
vector
of free terms (see Vector).

Return values

solutionVector
is a Vector of values that after dividing by
solutionDivisor
satisfy the system of equations, empty if the system is not solvable.
solutionDivisor
is a real number to divide the
solutionVector
by to get the solution, empty value if not solvable.
eigenvector
of the coefficient matrix if the system is solvable, empty otherwise (see Vector).
solvableCondition
is TRUE if the system is solvable, FALSE otherwise.

Complexity

O(size^3)

Example

"sl/algebra" useFile checkedSolve: [ m:v:;; m v solve [ drop d:; res:; "factor: " print d print LF print res.makeRange [print "," print] each LF print ] [ fv:; drop drop "fail, v: " print fv.makeRange [print "," print] each LF print ] if ] func; m1: ((2.0 1.0 1.0) (-5.0 1.0 2.0) (-1.0 0.666666 1.0)) makeMatrix; m2: ((3.0 1.0) (1.0 2.0) (2.0 1.0)) makeMatrix; m1 (1.0 3.0 2.0) makeVector checkedSolve m1 (-8.0 3.0 5.0) makeVector checkedSolve m2 (1.0 1.0) makeVector checkedSolve
Output:
fail, v: -0.111111,1.000000,-0.777778, factor: 1.000000 1.000000,2.000000,0.000000, factor: 1.000000 0.200000,0.400000,0.000000,