Suatu Matriks disebut mempunyai invers jika A.A-1 = Matriks identitas n.
Dapat disebut juga suatu matriks jika dikalikan dengan inversnya maka akan menghasilkan matriks identitas.
Dibawah ini merupakan prgram Invers Matriks untuk bahasa pemrograman PASCAL.
uses crt;
type matrik = object
emat, kof : array [1..3,1..3] of integer;
procedure input;
procedure tampil;
procedure invers;
procedure invers2;
procedure invers3;
end;
var i,j,ordo,det,pil : integer;
mat : matrik;
procedure matrik.input;
begin
writeln ;
writeln ('Masukan Ordo Matrik [2..3] : ');readln(ordo);
writeln ('Matriks Ordo ',ordo);
for i := 1 to ordo do
begin
for j := 1 to ordo do
begin
write ('Elemen [',i,',',j,'] = ');
readln (emat[i,j]);
end;
end;
end;
procedure matrik.tampil;
begin
writeln;
for i:=1 to ordo do
begin
for j:= 1 to ordo do
begin
write (emat[i,j]:5,' ');
end;
writeln;
end;
readln;
end;
procedure matrik.invers;
begin
if ordo = 2 then matrik.invers2
else matrik.invers3;
end;
procedure matrik.invers2;
begin
writeln;
det := (emat[1,1]*emat[2,2])-(emat[1,2]*emat[2,1]);
writeln ('Determinan Matrik = ',det);writeln;
writeln ('Matrik Inversnya :'); writeln;
writeln (emat[2,2],'/',det,' ','-',emat[1,2],'/',det);
writeln('-',emat[2,1],'/',det,' ',emat[1,1],'/',det);
readln;
end;
procedure matrik.invers3;
var detA, detB, det : integer;
begin
detA:= ((emat[1,1] * emat[2,2] * emat[3,3]) + (emat[1,2] * emat[2,3] * emat[3,1]) +(emat[1,3] * emat[2,1] * emat[3,2]));
detB:= ((emat[1,3] * emat[2,2] * emat[3,1]) + (emat[2,3] * emat[3,2] * emat[1,1]) +(emat[1,2] * emat[2,1] * emat[3,3]));
det := detA - detB;
writeln;writeln ('Determinan Matrik = ',det);writeln;
kof[1,1]:=(emat[2,2]*emat[3,3]) - (emat[3,2]*emat[2,3]);
kof[1,2]:=-((emat[2,1]*emat[3,3]) - (emat[2,3]*emat[3,1]));
kof[1,3]:=(emat[2,1]*emat[3,2]) - (emat[2,2]*emat[3,1]);
kof[2,1]:=-((emat[1,2]*emat[3,3]) - (emat[1,3]*emat[3,2]));
kof[2,2]:=(emat[1,1]*emat[3,3]) - (emat[1,3]*emat[3,1]);
kof[2,3]:=-((emat[1,1]*emat[3,2]) - (emat[1,2]*emat[3,1]));
kof[3,1]:=(emat[1,2]*emat[2,3]) - (emat[1,3]*emat[2,2]);
kof[3,2]:=-((emat[1,1]*emat[2,3]) - (emat[1,3]*emat[2,1]));
kof[3,3]:=(emat[1,1]*emat[2,2]) - (emat[1,2]*emat[2,1]);
writeln ('Matrik Adjoin :');writeln;
for i :=1 to 3 do
begin
for j:= 1 to 3 do
begin
write (kof[i,j]:8,' ');
end;
writeln;
end;
writeln;
writeln ('Matrik Invers :');writeln;
for i:= 1 to 3 do
begin
for j:= 1 to 3 do
begin
write (kof[i,j],'/',det,' ');
end;
writeln;
end;
readln;
end;
begin
repeat
clrscr;
gotoxy (25,1);writeln ('***** Menu Matrik *****');
gotoxy (25,2);writeln ('1. Input Matrik');
gotoxy (25,3);writeln ('2. Matrik Invers');
gotoxy (25,4);writeln ('3. Keluar');
gotoxy (25,5);writeln ('***********************');
gotoxy (27,6);write ('Pilihan [1..3] :');
readln(pil);
case pil of
1 : begin
mat.input;
mat.tampil;
end;
2 : mat.invers;
end;
until (pil) = 3;
end.
Untuk Sebagian orang mungkin membuat program Invers Matriks merupakan sebuah kendala. Semoga program diatas berguna bagi orang yang memerlukannya.
Wednesday, December 23, 2009
Program Invers Matriks PASCAL
Subscribe to:
Posts (Atom)