# Решение систем линейных алгебраических уравнений итерационными методами, страница 3

for i:=n downto 1 do

begin

SUM:=0;

for j:=i+1 to n do

SUM:=SUM+a[i,j]*x[j];

x[i]:=(b[i]-SUM);

end;

stat:=1;

end;

end.

Текстмодуля (U_iter):

unit u_ITER;

interface

uses UN_VVOD;

procedure ITER (a:matrix; b:vector; n:integer;eps:real;

var x:vector; var stat:integer);

implementation

procedure iter;

var i,j:integer;

r,SUM,max:real;

x0:vector;

begin

for  i:=1 to n do

begin

Sum:=0;

for j:=1 to n do

if j<>i  then   sum:=sum+a[i,j];

end;

if abs(a[i,j])<sum then

begin

writeln;

writeln('Ne shoditsya');

stat:=0;

exit;

end;

for i:=1 to n do

begin

for j:=1 to n do

if j<>i then a[i,j]:=a[i,j]/a[i,i];

b[i]:=b[i]/a[i,i];

a[i,i]:=0;

x0[i]:=b[i];

end;

repeat

for i:=1 to n do

begin

sum:=0;

for j:=1 to n do

sum:=sum+a[i,j]*x0[j];

x[i]:=sum+b[i];

end;

max:=0;

for i:=1 to n do

begin

r:= abs(x[i]-x0[i]);

if r>max then max:=r;

x0[i]:=x[i];

end;

until max<=eps;

end;

end.

Текстмодуля (U_koren):

unit U_Koren;

interface

uses UN_VVOD;

var

S:matrix;

y:vector;

i,j,m:integer;

sum:real;

procedure Koren(a:matrix; b:vector; n:integer; eps:real;

var x:vector; var stat:integer);

implementation

procedure Koren;

begin

for i:= 1 to n do

for j:= 1 to n do

if a[i,j]<>a[j,i] then

begin

writeln; writeln('Can not use this method for Matrix A');

end;

S[1,1]:=sqrt(abs(a[1,1]));

for j:=2 to n do S[1,j]:=a[1,j]/S[1,1];

for i:=2 to n do

begin

sum:=0;

for m:=1 to i-1 do  sum:=sum+sqr(S[m,i]);

S[i,i]:=sqrt(abs(a[i,i]-sum));

for j:=1 to n do

begin

sum:=0;

for m:=1 to i-1 do sum:=sum+S[m,i]*S[m,j];

if(i>j) then S[i,j]:=0 else S[i,j]:=(a[i,j]-sum)/S[i,i];

end;

end;

writeln('treugolnay matrica');

for i:=1 to n do

begin

for j:=1 to n do  write(s[i,j]:6:2);

writeln

end;

y[1]:=b[1]/s[1,1];

for i:=2 to n do

begin

sum:=0;

for m:=1 to i-1 do sum:=sum+s[m,i]*y[m];

y[i]:=(b[i]-sum)/s[i,i];

end;

for i:=n downto 1 do

begin

sum:=0;

for m:=i+1 to n do

sum:=sum+s[i,m]*x[m];

x[i]:=(y[i]-sum)/s[i,i];

end;

writeLn('   y             x');

for i:=1 to n do  writeLn(y[i]:10:5, '  ',x[i]:10:5);

end;

end.

Текст модуля (U_mkk):

Unit U_MKK;

interface

uses u_from;

procedure koren(A:Matrix;b:vector;var x:vector);

implementation

procedure koren;

var  t:Matrix;  k,i,j,i1:integer;  s,n,r:real;  y,e:vector;

l:array [Index] of integer;

begin

for i:=1 to mmax do

begin

for j:=1 to mmax do

begin

if i=j then

begin

if i=1 then

begin

t[1,1]:=sqrt(abs(a[1,1]));

if a[1,1]<0 then l[1]:=-1 else l[1]:=1;

end

else

begin

s:=0;i1:=i-1;

for k:=1 to i1 do

begin

r:=sqr(t[k,i]);  if l[k]=-1 then  r:=-r;