11/16/2016
Gauss Seidel Menggunakan Matriks
procedure TForm1.Button1Click(Sender: TObject);
var
A:array[0..2,0..2] of Real;
B:array[0..2,0..0] of Real;
n,i,j,k,l,m:Integer;
x0,y0,z0,x1,y1,z1,epsilon,c,d,e,e1,e2,e3:Real;
begin
with StringGrid1 do
for i:=0 to 2 do
for j:=0 to 2 do
A[j,i]:=StrToFloat(Cells[i,j]);
with StringGrid2 do
for i:=0 to 0 do
for j:=0 to 2 do
B[j,i]:=StrToFloat(Cells[i,j]);
epsilon:=StrToFloat(Edit1.Text);
x0:=StrToInt(Edit2.Text);
y0:=StrToFloat(Edit3.Text);
z0:=StrToFloat(Edit4.Text);
c:=Abs(A[0,1])+Abs(A[0,2]);
d:=Abs(A[1,0])+Abs(A[1,2]);
e:=Abs(A[2,0])+Abs(A[2,1]);
k:=0;
l:=0;
m:=0;
If (Abs(A[0,0])<c) and (Abs(A[1,1])<d) and (Abs(A[2,2])<e) then
ShowMessage ('Nilai tidak akan Konvergen, mohon masukkan kembali SPL yang memenuhi syarat awal')
else
begin
repeat
k:=k+1;
x1:=(B[0,0]+((-1*A[0,1])*y0)+((-1*A[0,2])*z0))/A[0,0];
e1:=Abs((x1-x0)/x1);
Listbox1.Items.Add(IntToStr(k));
Listbox2.Items.Add(FloatToStr(x1));
Listbox3.Items.Add(FloatToStr(e1));
l:=l+1;
y1:=(B[1,0]+((-1*A[1,0])*x1)+((-1*A[1,2])*z0))/A[1,1];
e2:=Abs((y1-y0)/y1);
Listbox4.Items.Add(IntToStr(l));
Listbox5.Items.Add(FloatToStr(y1));
Listbox6.Items.Add(FloatToStr(e2));
m:=m+1;
z1:=(B[2,0]+((-1*A[2,0])*x1)+((-1*A[2,1])*y1))/A[2,2];
e3:=Abs((z1-z0)/z1);
Listbox7.Items.Add(IntToStr(m));
Listbox8.Items.Add(FloatToStr(z1));
Listbox9.Items.Add(FloatToStr(e3));
If e3<=epsilon then Edit7.Text:=FloatToStr(z1) else z0:=z1;
If e2<=epsilon then Edit6.Text:=FloatToStr(y1) else y0:=y1;
If e1<=epsilon then Edit5.Text:=FloatToStr(x1) else x0:=x1;
Until (e1<=epsilon) or (e2<=epsilon) or (e3<=epsilon);
end;
Edit2.Text:=FloatToStr(x1);
Edit3.Text:=FloatToStr(y1);
Edit4.Text:=FloatToStr(z1);
end;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment