MODULE LinEqRe;
IMPORT Nbr := NbrRe, Vec := VecRe, Mtx := MtxRe, Errors := DataErrors;
TYPE
Solver* = OBJECT
VAR
PROCEDURE & Initialize*( VAR A: Mtx.Matrix );
END Initialize;
PROCEDURE Solve*( VAR b: Vec.Vector ): Vec.Vector;
END Solve;
END Solver;
PROCEDURE NormalizeVector*( VAR v: Vec.Vector; VAR mag: Nbr.Real );
VAR i: LONGINT; abs, zero: Nbr.Real;
BEGIN
IF v # NIL THEN
zero := 0; mag := zero;
FOR i := 0 TO v.lenx - 1 DO
abs := ABS( v.Get( i ) );
IF abs > mag THEN mag := abs END
END;
IF mag > MIN( Nbr.Real ) THEN
v.Divide( mag );
FOR i := 0 TO v.lenx - 1 DO
IF ABS( v.Get( i ) ) < Nbr.Epsilon THEN v.Set( i, zero ) END
END
ELSE
FOR i := 0 TO v.lenx - 1 DO v.Set( i, zero ) END
END
ELSE Errors.Error( "A NIL vector was passed as an argument." )
END
END NormalizeVector;
PROCEDURE NormalizeMatrix*( VAR m: Mtx.Matrix; VAR mag: Nbr.Real );
VAR i, j: LONGINT; abs, zero: Nbr.Real;
BEGIN
IF m # NIL THEN
zero := 0; mag := zero;
FOR i := 0 TO m.rows - 1 DO
FOR j := 0 TO m.cols - 1 DO
abs := ABS( m.Get( i, j ) );
IF abs > mag THEN mag := abs END
END
END;
IF mag > MIN( Nbr.Real ) THEN
m.Divide( mag );
FOR i := 0 TO m.rows - 1 DO
FOR j := 0 TO m.cols - 1 DO
IF ABS( m.Get( i, j ) ) < Nbr.Epsilon THEN m.Set( i, j, zero ) END
END
END
ELSE
FOR i := 0 TO m.rows - 1 DO
FOR j := 0 TO m.cols - 1 DO m.Set( i, j, zero ) END
END
END
ELSE Errors.Error( "A NIL matrix was passed as an argument." )
END
END NormalizeMatrix;
END LinEqRe.