BUAT YANG PERSAMAANNYA UDAH DITENTUIN nah KALO BELUM???
program metnum_gaus_seidel;
uses crt;
const n=3;
var
a : array [1..n,1..n] of real;
b,x : array [1..n] of real;
i,j,imax,lamda,sentinel,iter : integer;
es,ea,dummy,sum,old : real;
begin
clrscr;
a[1,1]:= 4;a[1,2]:=-1;a[1,3]:=1;b[1]:= 7;
a[2,1]:= 4;a[2,2]:=-8;a[2,3]:=1;b[2]:=-21;
a[3,1]:=-2;a[3,2]:= 1;a[3,3]:=5;b[3]:= 15;
x[1]:=1;x[2]:= 2;x[3]:=2;
es:=0.00001;
for i:=1 to n do
begin
dummy:=a[i,i];
for j:=1 to n do
a[i,j] := a[i,j]/dummy;
b[i]:=b[i]/dummy;
end;
for i:=1 to n do
begin
sum:=b[i];
for j:=1 to n do
if i<>j then
sum:=sum-a[i,j]*x[j];
x[i]:=sum;
end;
lamda:=1;iter:=0;
repeat
inc(iter);
sentinel:=1;
for i:=1 to n do
begin
old:=x[i];
sum:=b[i];
for j:=1 to n do
if i<>j then
sum:=sum-a[i,j]*x[j];
x[i]:=lamda*sum+(1-lamda)*old;
if (sentinel=1) and (x[i]<>0) then
begin
ea:=abs((x[i]-old)/x[i]);
if ea>es then
sentinel:=0;
end;
end;
until(sentinel=1);
writeln('nilai x : ',x[1]:8:5);
writeln('nilai y : ',x[2]:8:5);
writeln('nilai z : ',x[3]:8:5);
writeln('nilai ea : ',es:8:5);
writeln('nilai iterasi : ',iter);
readln;
end.
kembali ke halaman Metode Numerik