Senin, 30 Juni 2014

Mencari akar dari SPL 2x2 dengan Teorema Cayley-Hamilton

Algoritma Progam Pascal untuk Teorema Cayley-Hamilton pada Sistem Persamaan Linier
program cayley_hamilton;
uses wincrt;
var
   i, j, a, b, c, d, cek: integer;
   b0, b1               : real;
   e1, e2, e3           : array [1..2] of real;
   mA, mI               : array [1..2,1..2] of integer;
   akarA                : array [1..2,1..2] of real;
label 1, 2;

begin
{Input}
writeln('Masukkan entri matriks A');
for i:= 1 to 2 do
begin
     for j:= 1 to 2 do
     begin
          write('a',i,'',j,' = ');readln(mA[i,j]);
     end;
end;

for i:= 1 to 2 do
begin
     for j:= 1 to 2 do
     begin
          if j = i then mI[i,j]:= 1;
     end;
end;

{Cek definit positif atau definit negatif}
writeln('--------------------------------------------------');
writeln('Cek definit positif atau definit negatif:');
if mA[1,1]+mA[2,2] > mA[1,2]+mA[2,1] then writeln('Definit positif!');
if mA[1,1]+mA[2,2] < mA[1,2]+mA[2,1] then
begin
     writeln('Definit negatif!');
     goto 2;
end;

{Cari lamda}
writeln('--------------------------------------------------');
writeln('Nilai lamda:');
a:= mA[1,1]+mA[2,2];
b:= mA[1,1]*mA[2,2] - mA[1,2]*mA[2,1];
for i:= 1 to 1000 do
begin
     c:= a - i;
     d:= i;
     if c*d = b then
     begin
          cek:= 1;
          goto 1;
     end;    
end;
1:
if cek = 1 then writeln('lamda 1 = ',c,' dan lamda 2 = ',d);
if cek <> 1 then writeln('lamda tidak ditemukan.');

{Eliminasi}
writeln('--------------------------------------------------');
writeln('Hasil eliminasi:');
e1[1]:= sqrt(c);
e1[2]:= c;
e2[1]:= sqrt(d);
e2[2]:= d;
b1:= (e1[1] - e2[1])/(e1[2]-e2[2]);
b0:= e1[1] - (e1[2]*b1);
writeln('b0 = ',b0:0:6,' dan b1 = ',b1:0:6);

{Tahap akhir}
for i:= 1 to 2 do
begin
     for j:= 1 to 2 do
     begin
          akarA[i,j]:= (mA[i,j]*b1) + (mI[i,j]*b0);
     end;
end;

writeln('--------------------------------------------------');
writeln('Matriks akarA:');
for i:= 1 to 2 do
begin
     for j:= 1 to 2 do
     begin
          write(' ',akarA[i,j]:0:6);
     end;
     writeln;
end;

2:
end.


Preview Program:

Tidak ada komentar:

Posting Komentar

Related Posts Plugin for WordPress, Blogger...