<> <> <> DIRECTORY LinearSystem, Real USING [RealException], JaMFnsDefs USING [PushReal, GetReal, PushString, Register]; LinearSystemJaM: PROGRAM IMPORTS LinearSystem, Real, JaMFnsDefs = BEGIN OPEN JaMFnsDefs; Solve2: PROCEDURE = BEGIN singular:BOOLEAN _ FALSE; A: LinearSystem.Matrix2; b,x:LinearSystem.Column2; FOR i:NAT DECREASING IN [1..2] DO b[i] _ GetReal[] ENDLOOP; FOR i:NAT DECREASING IN [1..2] DO FOR j:NAT DECREASING IN [1..2] DO A[i][j] _ GetReal[]; 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[x[i]] ENDLOOP ELSE PushString["Singular!"L]; END; Solve3: PROCEDURE = BEGIN singular:BOOLEAN _ FALSE; A: LinearSystem.Matrix3; b,x:LinearSystem.Column3; FOR i:NAT DECREASING IN [1..3] DO b[i] _ GetReal[] ENDLOOP; FOR i:NAT DECREASING IN [1..3] DO FOR j:NAT DECREASING IN [1..3] DO A[i][j] _ GetReal[]; 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[x[i]] ENDLOOP ELSE PushString["Singular!"L]; END; Solve4: PROCEDURE = BEGIN singular:BOOLEAN _ FALSE; A: LinearSystem.Matrix4; b,x:LinearSystem.Column4; FOR i:NAT DECREASING IN [1..4] DO b[i] _ GetReal[] ENDLOOP; FOR i:NAT DECREASING IN [1..4] DO FOR j:NAT DECREASING IN [1..4] DO A[i][j] _ GetReal[]; 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[x[i]] ENDLOOP ELSE PushString["Singular!"L]; END; Solve5: PROCEDURE = BEGIN singular:BOOLEAN _ FALSE; A: LinearSystem.Matrix5; b,x:LinearSystem.Column5; FOR i:NAT DECREASING IN [1..5] DO b[i] _ GetReal[] ENDLOOP; FOR i:NAT DECREASING IN [1..5] DO FOR j:NAT DECREASING IN [1..5] DO A[i][j] _ GetReal[]; 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[x[i]] ENDLOOP ELSE PushString["Singular!"L]; END; Solve6: PROCEDURE = BEGIN singular:BOOLEAN _ FALSE; A: LinearSystem.Matrix6; b,x:LinearSystem.Column6; FOR i:NAT DECREASING IN [1..6] DO b[i] _ GetReal[] ENDLOOP; FOR i:NAT DECREASING IN [1..6] DO FOR j:NAT DECREASING IN [1..6] DO A[i][j] _ GetReal[]; 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[x[i]] ENDLOOP ELSE PushString["Singular!"L]; END; Register["LinearSystem.Solve2"L,Solve2]; Register["LinearSystem.Solve3"L,Solve3]; Register["LinearSystem.Solve4"L,Solve4]; Register["LinearSystem.Solve5"L,Solve5]; Register["LinearSystem.Solve6"L,Solve6]; END.