INVERS MATRIKS
program matriks_invers;
uses wincrt;
var n,i,j,x,y,k,l,m: integer;
a:array[1..20,1..20] of real;
begin
{gotoxy (10,1);}
writeln ('Program Pencarian Invers Matriks');
writeln;
writeln ('Masukkan ordo matrik (n x n).');
write ('n : ');
readln (n);
writeln;
for i:=1 to n do
begin
for j:=1 to n do
begin
write ('A(',i,',',j,') : ');
readln (a[i,j]);
end;
end;
writeln;
for i:=1 to n do
begin
for j:=1 to n do
write (' ',a[i,j]:0:0);
writeln;
end;
{MATTRIK SISI KANAN}
for j:=n+1 to n+n do
begin
i:=j-n;
a[i,j]:=1;
end;
for j:=n+1 to n+n do
begin
for i:=1 to n do
if i<>j-n then a[i,j]:=0;
end;
{PROSES PENGINVERSAN}
for i:=1 to n do
begin
for j:=1 to n+n do
begin
if i<>j then a[i,j]:=a[i,j]/a[i,i];
end;
for j:=1 to n+n do
begin
if i=j then a[i,j]:=1;
end;
{PENJUMLAHAN KESATU BARIS ELEMENT}
for l:=1 to n do
begin
if i<>l then
begin
for j:=i+1 to n+n do
begin
a[l,j]:=a[l,j]-(a[i,j]*a[l,i]);
end;
end;
end;
{PEMBUATAN NOL DISEKITAR MATRIKS KIRI}
for k:=1 to n do
begin
if i<>k then
begin
a[k,i]:=0;
end;
end;
end;
{PENCETAKAN}
readln;
writeln('Maka invers dari matrik adalah :');
for i:=1 to n do
begin
for j:=n+1 to n+n do
write (' ',a[i,j]:0:2);
writeln;
end;
readln;
end.
0 komentar:
Post a Comment