home *** CD-ROM | disk | FTP | other *** search
- program Solveq; { Linear Equation Solver}
- uses crt;
-
- const
- NumEqn = 3; {Mod. #1}
-
- { The above constant must be set correctly by you. }
- { NumEqn = The number of equations to be solved. }
-
- NumEqnPlus1 = NumEqn + 1;
- ColSize = NumEqnPlus1;
- RowSize = NumEqn;
- MatrixSize = NumEqn;
-
- type
- Array2Type = array[1..RowSize, 1..ColSize] of real;
- MatrixType = array[1..MatrixSize, 1..MatrixSize] of real;
-
- var
- EqnArray : Array2Type;
- EqnCount, J, K : integer;
- OK : boolean;
- Reply : char;
- CoeffMatrix, RHSMatrix, InvertedMatrix : MatrixType;
- AnswerMatrix : MatrixType;
-
- {$I GetReply.PSL}
- {$I Key2Arr.PSL}
- {$I MatInv.PSL}
- {$I MatMult.PSL}
- {$I Show2Arr.PSL}
- {$I WaitKey.PSL}
-
- BEGIN
- clrscr;
- writeln('SIMULEQN - A simultaneous linear equation solver');
- writeln;
- if (NumEqnPlus1 <> NumEqn + 1) or (NumEqn < 1) then
- begin
- writeln(chr(7));
- writeln('** Bad settings in the const block **');
- exit
- end;
- writeln('The program is currently set to do', NumEqn:2,
- ' equations in', NumEqn:2, ' unknowns.');
- writeln;
- writeln('The data must now be input. You will be prompted');
- writeln('for the coefficients and right-hand side of each');
- writeln('equation (or row) one at a time. The notation');
- writeln('Entry [A,B] means coefficient B of equation A.');
- writeln('When B =', NumEqnPlus1:2,
- ', provide the right-hand side.');
- Reply := '0';
- repeat
- writeln;
- EqnCount := 0;
- Key2Arr(EqnArray, EqnCount);
- writeln;
- writeln('You now have a chance to review the data.');
- WaitKey;
- Show2Arr(EqnArray, EqnCount, 8, 4, 4);
- writeln;
- writeln('This is the data you entered. Is it correct?');
- writeln;
- writeln(' 1 - Yes it is; please continue.');
- writeln(' 2 - No it''s not; let me reenter it.');
- writeln(' 3 - No it''s not; please abort the program.');
- writeln;
- GetReply('1', '3', Reply);
- writeln(Reply)
- until
- Reply <> '2';
- if Reply = '3' then
- exit;
- writeln;
- for J := 1 to NumEqn do
- for K := 1 to NumEqn do
- CoeffMatrix[J,K] := EqnArray[J,K];
- for J := 1 to NumEqn do
- RHSMatrix[J,1] := EqnArray[J,NumEqnPlus1];
- for J := 1 to NumEqn do
- for K := 2 to NumEqn do
- RHSMatrix[J,K] := 0.0;
- MatInv(CoeffMatrix, InvertedMatrix, OK);
- if not OK then
- begin
- writeln(chr(7));
- writeln('Bad input, no solution is possible.');
- exit
- end;
- MatMult(InvertedMatrix, RHSMatrix, AnswerMatrix);
- writeln('The solution is');
- writeln;
- for J := 1 to NumEqn do
- writeln('Unknown', J:2, ' = ', AnswerMatrix[J,1])
- END.
-