//Determinan Matriks 3x3
#include <iostream.h>
#include <conio.h>
#define Nmaks 4
void main()
{
typedef float matriks[Nmaks][Nmaks];
int i,j,determinan;
matriks A,a,C,c;
char answer;
do
{
do
{
clrscr();
cout<<"DETERMINAN MATRIKS A : "<<endl<<endl;
cout<<"Masukkan Nilai Matriks A : "<<endl;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
cout<<"A["<<i<<","<<j<<"] = ";
cin>>A[i][j];
}
}
clrscr();
cout<<endl;
//Proses Mencari Determinan Matriks A
determinan = ((A[1][1]*A[2][2]*A[3][3])+(A[1][2]*A[2][3]*A[3][1])+(A[1][3]*A[2][1]*A[3][2])) -
((A[3][1]*A[2][2]*A[1][3])+(A[3][2]*A[2][3]*A[1][1])+(A[3][3]*A[2][1]*A[1][2]));
}while (determinan == 0);
//Setelah Mendapat Determinannya, sekarang kita cari Kofaktornya
C[1][1] = (A[2][2]*A[3][3] - A[3][2]*A[2][3]);
C[1][2] = -1 * (A[2][1]*A[3][3] - A[3][1]*A[2][3]);
C[1][3] = (A[2][1]*A[3][1] - A[3][1]*A[2][2]);
C[2][1] = -1 * (A[1][2]*A[3][3] - A[3][2]*A[1][3]);
C[2][2] = (A[1][1]*A[3][3] - A[3][1]*A[1][3]);
C[2][3] = -1 * (A[1][1]*A[3][2] - A[3][1]*A[1][2]);
C[3][1] = (A[1][2]*A[2][3] - A[2][2]*A[2][3]);
C[3][2] = -1 * (A[1][1]*A[2][3] - A[2][1]*A[1][3]);
C[3][3] = (A[1][1]*A[2][2] - A[2][1]*A[1][2]);
//Setelah Mendapatkan Kofaktornya, sekarang kita mencari Adjoint Matrix A
//Dimana Adjoint Matriks A adalah Transpose dari Kofaktor Matriks A
c[1][1] = C[1][1]; c[2][1] = C[1][2]; c[3][1] = C[1][3];
c[1][2] = C[2][1]; c[2][2] = C[2][2]; c[3][2] = C[2][3];
c[1][3] = C[3][1]; c[2][3] = C[3][2]; c[3][3] = C[3][3];
//Setelah Mendapatkan Kofaktor Matriks A, sekarang kita bisa mencari nilai Invers Matrix A
//Dimana Invers Matrix A adalah hasil bagi antara Adjoint dengan Determinan Matrix A
a[1][1] = c[1][1]/determinan;
a[1][2] = c[1][2]/determinan;
a[1][3] = c[1][3]/determinan;
a[2][1] = c[2][1]/determinan;
a[2][2] = c[2][2]/determinan;
a[2][3] = c[2][3]/determinan;
a[3][1] = c[3][1]/determinan;
a[3][2] = c[3][2]/determinan;
a[3][3] = c[3][3]/determinan;
clrscr();
//Output Matriks A
gotoxy(1,5);
cout<<"A = ";
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
gotoxy(2+5*j,1+2*i);
cout<<A[i][j];
}
}
gotoxy(1,8);
cout<<"Determinan Matriks A = "<<determinan;
//Output Kofaktor Matriks A
gotoxy(1,10);
cout<<"Determinan Matriks A ";
gotoxy(1,15);
cout<<"KoA = ";
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
gotoxy(1+7*j,11+2*i);
cout<<C[i][j];
}
}
//Output Adjoint Matriks A
gotoxy(1,19);
cout<<"Adjoint Matriks A ";
gotoxy(1,24);
cout<<"Adj = ";
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
gotoxy(1+7*j,20+2*i);
cout<<c[i][j];
}
}
//Output Invers Matriks A
gotoxy(1,27);
cout<<"Invers Matriks A ";
gotoxy(1,32);
cout<<"A^-1 = ";
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
gotoxy(1+9*j,28+2*i);
cout<<a[i][j];
}
}
getch();
clrscr();
cout<<"== PROGRAM SELESAI =="<<endl<<endl;
cout<<"Mau Melakukan Perhitungan Lagi?? [Y/T] "; cin>>answer;
}
while ((answer == 'y') || (answer == 'Y'));
}
Tidak ada komentar:
Posting Komentar