MATRIX INVERS dengan Delphi

Selasa, 30 Maret 2010


procedure TForm1.Button1Click(Sender: TObject);

var

n,i,j,k,bar1,kol1:integer;

a,b:array [1..100,1..100]of real;

x,c:array [1..100]of real;

faktor,sum:real;

begin

memo1.Clear;

n:=stringgrid2.RowCount-1;


//memasukkan matrix a dan c

for i:=1 to n do

for j:=1 to 2*n do

begin

a[i,j]:=strtofloat(stringgrid1.cells[j,i]);

c[i]:= strtofloat(stringgrid1.cells[(2*n)+1,i]);

end;


//mulai eliminasi gauss-jordan

for k:=1 to n do

begin


faktor:=a[k,k];

for j:=1 to 2*n do

begin

a[k,j]:=a[k,j]/faktor;

end;





for i:=1 to 2*n do

begin

if i<>k then

begin

faktor:=a[i,k];

for j:=1 to 2*n do

begin

a[i,j]:=a[i,j]-faktor*a[k,j];

end;

end;

end;

end;


//mengeluarkan invers

for bar1:=1 to n do

for kol1:=1 to 2*n do

stringgrid2.cells[kol1,bar1]:=floattostr(a[bar1,kol1]);


//menghitung x[i]

for i:=1 to n do

begin

sum:=0;

for j:=1 to n do

begin

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

end;

x[i]:=sum;

memo1.lines.add('x'+inttostr(i)+' = '+floattostr(x[i]));

end;

end;

Share this Article on :

1 komentar:

cintamatika mengatakan...

Tolong tampilkan gambarnya gan, gambarnya gak kelihatan jadi susah buatnya??

Posting Komentar

LinkWithin

Related Posts Plugin for WordPress, Blogger...
 

© Copyright Ngidup Buat Ngakhirat 2010 -2011 | Design by Herdiansyah Hamzah | Published by Borneo Templates | Powered by Blogger.com.