Я написал прогу, но она не работает.
Вот алгоритм: АХ=В- исходная система, Х=GX+F- эквивалентная ей система, где
G=E-(A^t*A)/нормуA^t*A
. F=A^t*B/норуA^t*A
нормаA^t*A=максимальная сумма элементов строки.
A^t- транспонированая матрица
X1=GX0+F {X0=F}
X1-X0—невязка(точность)
X2=GX1+F
X2-X1
X3=GX2+F
X3-X2
И т.д.
Код
program metod_iteracii;
Uses CRT;
type
matrica=array [1..4,1..4] of extended;
matrica1=array [1..4,1..1] of real;
var
R,G,G1,w,a,at,ata,e:matrica;
t,i,j,m,n,l,k:byte;
x,d,raz,c,b,b1,f,f1:matrica1;
max,max1,s:real;
procedure udo;{privedenie sistemi k vidu udobnomu dli iteracii}
begin
for i:=1 to n do
for j:=1 to m do
begin
s:=0;
at[j,i]:=s+a[i,j]; {tranponirue matricu}
end;
writeln('matrica a ');
for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j]:2:2,' ');
readln;
end;
writeln('matrica яtranponirovanay');
for i:=1 to n do
begin
for j:=1 to m do
write(at[i,j]:2:2,' ');
readln;
end;
{------------------------------}
for i:=1 to n do
for j:=1 to l do
begin
s:=0;
for k:=1 to m do
s:=s+a[i,k]*at[k,j]; {matrica=A*A tranponirovanai}
ata[i,j]:=s;
end;
writeln('matrica at*a ');
for i:=1 to n do
begin
for j:=1 to m do
write(ata[i,j]:2:2,' ');
readln;
end;
{-----------------------}
for i:=1 to n do
begin
s:=0;
begin
for j:=1 to m do
s:=s+abs(ata[i,j]); { vichislenie normirovanoi matrici}
w[i,1]:=s;
end;
end;
{--------------------------}
{ writeln('normirovanay matrica ');
for i:=1 to n do
begin
write(w[i,1]:2:2,' ');
writeln;
end;}
{-----------------------}
max:=0;
for i:=1 to n do
begin
for j:=1 to m do
if w[i,j]>max then
max:=w[i,j];
end;
writeln('norma=', max:2:4);
{-----------------------------}
for i:=1 to n do
begin
for j:=1 to m do
G[i,j]:=e[i,j]-(1/max)*ata[i,j]; {vichislenie matrici G}
end;
{-----------------}
writeln('G ');
for i:=1 to n do
begin
for j:=1 to m do
write(G[i,j]:2:5,' ');
readln;
end;
{---------------------}
for i:=1 to n do
begin
s:=0;
for k:=1 to m do
s:=s+at[i,k]*b[k,1]*(1/max); {vichislenie matrico F}
f[i,1]:=s;
end;
writeln('matrica f ');
for i:=1 to n do
begin
write(f[i,1]:2:5,' ');
writeln;
end;
f1:=f;
end;
{-------------------------}
{----------------------}
procedure iterac(f:matrica1);
begin
for i:=1 to n do
for j:=1 to l do
begin
s:=0;
for k:=1 to m do
s:=s+G[i,k]*f[k,1];{G*X}
c[i,j]:=s;
end;
{------------------------------------------------------}
writeln ('matrica c=G*f');
for i:=1 to n do
write(c[i,1]:2:2,' ');
writeln;
{-------------------------------------------------}
begin
for i:=1 to m do
for j:=1 to n do
x[i,j]:=c[i,j]+f1[i,j];
end;
writeln('matrica x');
for i:=1 to l do
write('x[',i,'1]=', x[i,1]:2:4,' ');
writeln;
{---------------------------------------------------}
begin
for i:=1 to m do
for j:=1 to n do
raz[i,j]:=(x[i,j])-(f[i,j]); {nevyzca}
end;
writeln('matrica raz');
for i:=1 to l do
write( raz[i,1]:2:4,' ');
writeln;
{--------------------------------------}
begin
max:=abs(raz[1,1]); {nahodim max nevyzcu}
for i:=1 to m do
if abs(raz[i,1])>max then max:=abs(raz[i,1]);
end;
write('max=',max:2:4,' ' );
readln;
begin
if Abs(max)>0.00001 then
begin
f[i,j]:=x[i,j];
iterac(x);
end
else begin
writeln('matrica x ');
for i:=1 to l do
write(x[i,1]:2:4,' ');
writeln;
end;
end;
end;
procedure proverca;
begin
for i:=1 to n do
begin
R[i,m]:=A[i,1]*x[1,1]+A[i,2]*x[2,1]+A[i,3]*x[3,1]+A[i,4]*x[4,1];
writeln('b[',i,m,']=',R[i,m]:2:2);
end;
end;
BEGIN
n:=4;l:=4; m:=4;
a[1,1]:=3.51; a[1,2]:=0.17; a[1,3]:=3.68; a[1,4]:=-0.28;
a[2,1]:=4.52; a[2,2]:=2.11; a[2,3]:=6.63; a[2,4]:=-0.12;
a[3,1]:=-2.11; a[3,2]:=3.17; a[3,3]:=1.06; a[3,4]:=-0.15;
a[4,1]:=3.17; a[4,2]:=1.81; a[4,3]:=-3.17; a[4,4]:=0.22;
e[1,1]:=1; e[1,2]:=0; e[1,3]:=0; e[1,4]:=0;
e[2,1]:=0; e[2,2]:=1; e[2,3]:=0; e[2,4]:=0;
e[3,1]:=0; e[3,2]:=0; e[3,3]:=1; e[3,4]:=0;
e[4,1]:=0; e[4,2]:=0; e[4,3]:=0; e[4,4]:=1;
b[1,1]:=0.75;
b[2,1]:=1.11;
b[3,1]:=0.21;
b[4,1]:=0.05;
{ a[1,1]:=0.63; a[1,2]:=1.00; a[1,3]:=0.71; a[1,4]:=0.34;
a[2,1]:=1.17; a[2,2]:=0.18; a[2,3]:=0.65; a[2,4]:=0.71;
a[3,1]:=1.80; a[3,2]:=1.18; a[3,3]:=1.36; a[3,4]:=-2.35;
a[4,1]:=3.58; a[4,2]:=0.21; a[4,3]:=3.45; a[4,4]:=-1.18;
b[1,1]:=2.08;
b[2,1]:=0.17;
b[3,1]:=1.28;
b[4,1]:=0.05;}
udo;
iterac(f);
proverca;
END.