uses crt;
const
nn = 10;
type
Matrix = array[1..NN,1..NN+1] of real;
(* построчный ввод матрицы *)
Procedure ReadMatr(var A:Matrix; var n:word );
var
i, j, m: word;
begin
repeat
write('Введите количество линейных уравн. в системе: '); readln(N)
until (N>0) and (N<=NN);
m:=n+1;
For i:=1 to n do begin
For j:=1 to m do begin
write('A[',i,j,']= '); readln(A[i,j])
end
end
end;
(* построчный вывод матрицы *)
Procedure PrintMatr(A:Matrix; n:word);
Var
i, j, m: word;
begin
m:=n+1;
For i:=1 to n do begin
For j:=1 to m do write(A[i,j],' ');
writeln
end
end;
procedure GaussM(a:matrix;n:word; var s:byte; var x:array of real);
var
i, k, j: byte;
m, t: real;
begin
i:=1;
s:=1;
repeat
j:=i+1;
k:=i;
m:=abs(a[i,i]);
repeat
if m<abs(a[j,i]) then begin
m:=abs(a[j,i]);
k:=j;
end;
j:=j+1
until not(j<=n);
if m<>0 then begin
j:=i;
repeat
t:=a[i,j];
a[i,j]:=a[k,j];
a[k,j]:=t;
j:=j+1
until not(j<=n+1);
k:=i+1;
repeat
t:=a[k,i]/a[i,i];
a[k,i]:=0;
j:=i+1;
repeat
a[k,j]:=a[k,j]-t*a[i,j];
j:=j+1
until not(j<=n+1);
k:=k+1
until not(k<=n);
end
else begin
s:=0;
end;
i:=i+1
until not((i<=n)and(s=1));
if s=1 then begin
i:=n;
repeat
x[i]:=a[i,n+1];
j:=i+1;
while j<=n do begin
x[i]:=x[i]-a[i,j]*x[j];
j:=j+1;
end;
x[i]:=x[i]/a[i,i];
i:=i-1
until not(i>=1);
end;
end;
var
b: array[0..nn] of real;
a: Matrix;
n, j: word;
s: byte;
Begin
readmatr(a,n);
printmatr(a,n);
writeln('press any key'); readkey;
GaussM(a,n,s,b);
for j:=1 to n do write (b[j],' ');
writeln('press any key for exit ...'); readkey
end.
Решение систем, линейных уравнений |