Download LA System User Manual - Computer Graphics and Visualization
Transcript
LA System user manual – version 20090818
SolveLinearEqns[$eqnspos,$solvevars]:=
eqns2aug[$solvevars] (* matrix is one level deeper than result of eqns2aug *)
Code[$matpos = Append[$eqnspos, 1]] GuassElim[$matpos]
aug2eqns GuassElim consists of a forward pass and a backward pass. GaussElim[$matpos]:= ForwardPass[$matpos],
BackwardPass[$matpos] The forward pass repeats a number of steps (ForwardSteps), and for each step one more row is covered up ($coveredrows) at the top of the matrix. Each iteration will create a column with a pivot with value 1 in the top row (the first uncovered row) and zeroes below it. ForwardPass[$matpos] := Code[
$mat=Extract[$CurrentTerm, $matpos];
$range=Range[0, Length[$mat]1]
]
ForAll[$coveredrows,$range,ForwardSteps,$matpos,$coveredrows]]
ForwardSteps[$matpos,$coveredrows] :=
FindColumnJ[$matpos,$coveredrows,$j],
ExchangeNonZero[$matpos,$coveredrows,$j],
ScaleToOne[$matpos,$coveredrows,$j],
MakeZeroesFP[$matpos,$coveredrows,$j]
FindColumnJ determines the value of $j such that column $j is the first column with a nonzero value in it, or fails if no such column exists. FindColumnJ[$matpos, $coveredrows,$j]:=
Code[ $mat=Extract[$CurrentTerm, $matpos];
If[$coveredrows>=Length[$mat],$Failure,
$m=Transpose[Drop[List@@$mat,$coveredrows]];
$j=SelectIndex[$m,!zerovector[#]&];
If[$j==={},$Failure,$j=$j[[1]]]
]
]
If column $j has a zero in the first uncovered row, ExchangeNonZero swaps that row (using rewrite rule swaprows) with the next row that has a nonzero entry, if possible. In the implementation, if entry in the first uncovered row is nonzero, then $row1==$row2 and no swap is applied. 27