Sabtu, 02 April 2011

Program C++ Set Persamaan Matriks

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();


int a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,c1,c2,c3,c4,c5,c6,c7,d1,d2,d3,e,
f1,f2,f3,f4,f5,f6,f7,f8,f9,x1,x2,x3;
printf ("Format 3 Persamaan dengan 3 variabel\n\n");
printf ("(X1)a1 + (X2)b1 + (X3)c1 = d1\n");
printf ("(X1)a2 + (X2)b2 + (X3)c2 = d2\n");
printf ("(X1)a3 + (X2)b3 + (X3)c3 = d3\n\n");
printf ("Nilai a1=");scanf("%i",&a1);
printf ("Nilai a2=");scanf("%i",&a2);
printf ("Nilai a3=");scanf("%i",&a3);
printf ("Nilai b1=");scanf("%i",&b1);
printf ("Nilai b2=");scanf("%i",&b2);
printf ("Nilai b3=");scanf("%i",&b3);
printf ("Nilai c1=");scanf("%i",&c1);
printf ("Nilai c2=");scanf("%i",&c2);
printf ("Nilai c3=");scanf("%i",&c3);
printf ("Nilai d1=");scanf("%i",&d1);
printf ("Nilai d2=");scanf("%i",&d2);
printf ("Nilai d3=");scanf("%i",&d3);
printf ("\nMaka Bentuk persamaannya\n");
printf ("(X1)%i",a1);
printf (" + (X2)%i",b1);
printf (" + (X3)%i",c1);
printf (" = %i\n",d1);
printf ("(X1)%i",a2);
printf (" + (X2)%i",b2);
printf (" + (X3)%i",c2);
printf (" = %i\n",d2);
printf ("(X1)%i",a3);
printf (" + (X2)%i",b3);
printf (" + (X3)%i",c3);
printf (" = %i\n",d3);
printf ("Dalam Bentuk Matriksnya\n\n");
printf ("| %3i",a1);
printf ("   %3i",b1);
printf ("   %3i |\n",c1);
printf ("| %3i",a2);
printf ("   %3i",b2);
printf ("   %3i |\n",c2);
printf ("| %3i",a3);
printf ("   %3i",b3);
printf ("   %3i |\n",c3);
f1=(b2*c3)-(c2*b3);
f2=-((a2*c3)-(c2*a3));
f3=(a2*b3)-(b2*a3);
f4=-((b1*c3)-(c1*b3));
f5=(a1*c3)-(c1*a3);
f6=-((a1*b3)-(b1*a3));
f7=(b1*c2)-(c1*b2);
f8=-((a1*c2)-(c1*a2));
f9=(a1*b2)-(b1*a2);

printf ("\nMatriks baru (Matriks C)\n\n");
printf ("| %3i",f1);
printf ("   %3i",f2);
printf ("   %3i |\n",f3);
printf ("| %3i",f4);
printf ("   %3i",f5);
printf ("   %3i |\n",f6);
printf ("| %3i",f7);
printf ("   %3i",f8);
printf ("   %3i |",f9);
printf ("\n\nInvers Matriks C\n\n");
printf ("| %3i",f1);
printf ("   %3i",f4);
printf ("   %3i |\n",f7);
printf ("| %3i",f2);
printf ("   %3i",f5);
printf ("   %3i |\n",f8);
printf ("| %3i",f3);
printf ("   %3i",f6);
printf ("   %3i |\n",f9);
a4=a1*((b2*c3)-(c2*b3));
b4=-(b1*((a2*c3)-(c2*a3)));
c4=c1*((a2*b3)-(b2*a3));
e=a4+b4+c4;
a5=(f1*d1)/e;
b5=(f4*d2)/e;
c5=(f7*d3)/e;
a6=(f2*d1)/e;
b6=(f5*d2)/e;
c6=(f8*d3)/e;
a7=(f3*d1)/e;
b7=(f6*d2)/e;
c7=(f9*d3)/e;
printf ("\n\nInvers Akhir Untuk mendapatkan X1, X2, X3\n\n");
printf ("| %3i",a5);
printf ("   %3i",b5);
printf ("   %3i |\n",c5);
printf ("| %3i",a6);
printf ("   %3i",b6);
printf ("   %3i |\n",c6);
printf ("| %3i",a7);
printf ("   %3i",b7);
printf ("   %3i |\n",c7);

x1=a5+b5+c5;
x2=a6+b6+c6;
x3=a7+b7+c7;

printf ("\n\nNilai X1= %i\n",x1);
printf ("Nilai X1= %i\n",x2);
printf ("Nilai X1= %i\n",x3);

getch();
}

2 komentar: