LinearSystemJaM.mesa
Written by Michael Plass, 8-Oct-81
Last edit by Michael Plass, December 2, 1982 11:05 am
Last edit by Maureen Stone February 8, 1984 6:35:43 pm PST (Cedar5.1 and new JaM)
DIRECTORY
LinearSystem,
Real USING [RealException],
Rope USING [ROPE],
JaM USING [PushReal, PopReal, PushRope, Register, RegisterInit, State];
LinearSystemJaM: CEDAR PROGRAM IMPORTS LinearSystem, Real, JaM =
BEGIN OPEN JaM;
Solve2:
PROCEDURE[s: State] =
BEGIN
singular:BOOLEAN ← FALSE;
A: LinearSystem.Matrix2; b,x:LinearSystem.Column2;
FOR i:NAT DECREASING IN [1..2] DO b[i] ← PopReal[s] ENDLOOP;
FOR i:
NAT
DECREASING
IN [1..2]
DO
FOR j:
NAT
DECREASING
IN [1..2]
DO
A[i][j] ← PopReal[s];
ENDLOOP
ENDLOOP;
x ← LinearSystem.Solve2[
A,b!
Real.RealException => CHECKED {singular←TRUE; CONTINUE}];
IF
NOT singular
THEN
FOR i:NAT IN [1..2] DO PushReal[s,x[i]] ENDLOOP
ELSE PushRope[s,"Singular!"];
END;
Solve3:
PROCEDURE[s: State] =
BEGIN
singular:BOOLEAN ← FALSE;
A: LinearSystem.Matrix3; b,x:LinearSystem.Column3;
FOR i:NAT DECREASING IN [1..3] DO b[i] ← PopReal[s] ENDLOOP;
FOR i:
NAT
DECREASING
IN [1..3]
DO
FOR j:
NAT
DECREASING
IN [1..3]
DO
A[i][j] ← PopReal[s];
ENDLOOP
ENDLOOP;
x ← LinearSystem.Solve3[
A,b!
Real.RealException => CHECKED {singular←TRUE; CONTINUE}];
IF
NOT singular
THEN
FOR i:NAT IN [1..3] DO PushReal[s,x[i]] ENDLOOP
ELSE PushRope[s,"Singular!"];
END;
Solve4:
PROCEDURE[s: State] =
BEGIN
singular:BOOLEAN ← FALSE;
A: LinearSystem.Matrix4; b,x:LinearSystem.Column4;
FOR i:NAT DECREASING IN [1..4] DO b[i] ← PopReal[s] ENDLOOP;
FOR i:
NAT
DECREASING
IN [1..4]
DO
FOR j:
NAT
DECREASING
IN [1..4]
DO
A[i][j] ← PopReal[s];
ENDLOOP
ENDLOOP;
x ← LinearSystem.Solve4[
A,b!
Real.RealException => CHECKED {singular←TRUE; CONTINUE}];
IF
NOT singular
THEN
FOR i:NAT IN [1..4] DO PushReal[s,x[i]] ENDLOOP
ELSE PushRope[s,"Singular!"];
END;
Solve5:
PROCEDURE[s: State] =
BEGIN
singular:BOOLEAN ← FALSE;
A: LinearSystem.Matrix5; b,x:LinearSystem.Column5;
FOR i:NAT DECREASING IN [1..5] DO b[i] ← PopReal[s] ENDLOOP;
FOR i:
NAT
DECREASING
IN [1..5]
DO
FOR j:
NAT
DECREASING
IN [1..5]
DO
A[i][j] ← PopReal[s];
ENDLOOP
ENDLOOP;
x ← LinearSystem.Solve5[
A,b!
Real.RealException => CHECKED {singular←TRUE; CONTINUE}];
IF
NOT singular
THEN
FOR i:NAT IN [1..5] DO PushReal[s,x[i]] ENDLOOP
ELSE PushRope[s,"Singular!"];
END;
Solve6:
PROCEDURE[s: State] =
BEGIN
singular:BOOLEAN ← FALSE;
A: LinearSystem.Matrix6; b,x:LinearSystem.Column6;
FOR i:NAT DECREASING IN [1..6] DO b[i] ← PopReal[s] ENDLOOP;
FOR i:
NAT
DECREASING
IN [1..6]
DO
FOR j:
NAT
DECREASING
IN [1..6]
DO
A[i][j] ← PopReal[s];
ENDLOOP
ENDLOOP;
x ← LinearSystem.Solve6[
A,b!
Real.RealException => CHECKED {singular←TRUE; CONTINUE}];
IF
NOT singular
THEN
FOR i:NAT IN [1..6] DO PushReal[s,x[i]] ENDLOOP
ELSE PushRope[s,"Singular!"];
END;
Init:
PROC [s: State] = {
Register[s,"LinearSystem.Solve2",Solve2];
Register[s,"LinearSystem.Solve3",Solve3];
Register[s,"LinearSystem.Solve4",Solve4];
Register[s,"LinearSystem.Solve5",Solve5];
Register[s,"LinearSystem.Solve6",Solve6];
};
RegisterInit["LinearSystemJaM", Init];
END.