Matriks

package UAS;

import javax.swing.JOptionPane;

/**
*
* @author NURUL C.
*/
public class Menu_Matrik2011420007 {
public static void main(String[] args) {
String matrik_1 = JOptionPane.showInputDialog(“Masukkan Jumlah Baris : “);
int baris = Integer.parseInt(matrik_1);
String matrik_2= JOptionPane.showInputDialog(“Masukkan Jumlah Kolom : “);
int kolom = Integer.parseInt(matrik_2);
int A [][]= new int[baris][kolom];
int B [][]= new int[baris][kolom];
int C [][]= new int[baris][kolom];
JOptionPane.showMessageDialog(null, “Matrik A”);
System.out.println(“Matrik A”);
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
String matrik = JOptionPane.showInputDialog(“Masukkan baris ke-[“+(i+1)+”], kolom ke-[“+(j+1)+”] : “);
A[i][j] = Integer.parseInt(matrik);
System.out.print(” “+A[i][j]+” “);
}
System.out.println(“|”);
}
System.out.println(” “);
JOptionPane.showMessageDialog(null, “Matrik B”);
System.out.println(“Matrik B”);
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
String matrik = JOptionPane.showInputDialog(“Masukkan bil baris ke-[“+(i+1)+”], kolom ke-[“+(j+1)+”] : “);
B[i][j] = Integer.parseInt(matrik);
System.out.print(” “+B[i][j]+” “);
}
System.out.println(“|”);
}
System.out.println(” “);
System.out.println(”        MENU        “);
System.out.println(“——————–“);
String matrik = JOptionPane.showInputDialog(”       —MENU—    ” + “\n” + “\n”
+ “1.  PENJUMLAHAN [+]” + “\n”
+ “2.  PENGURANGAN [-]” + “\n”
+ “3.  PERKALIAN [x]” + “\n”
+ “4.  PEMBAGIAN [:]” + “\n”
+ “5.  TRANSPOSE” + “\n”
+ “6.  INVERS” + “\n”
+ “7.  CRAMMER” + “\n”
+ “8.  GAUSS” + “\n”
+ “9.  DETERMINAN” + “\n”
+ “10. Exit” + “\n” +”\n”);

System.out.println(“Hasil dari- : “);
int pilih = Integer.parseInt(matrik);
if(pilih == 1){
JOptionPane.showMessageDialog(null, “PENJUMLAHAN [+]”);
System.out.println(“1. PENJUMLAHAN”);
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
C[i][j]= A[i][j]+B[i][j];
System.out.print(” ” +C[i][j]+” “);
}
System.out.println(“|”);
}
}
if(pilih == 2){
JOptionPane.showMessageDialog(null, “PENGURANGAN [-]”);
System.out.println(“2. PENGURANGAN”);
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
C[i][j]=A[i][j]-B[i][j];
System.out.print(” “+C[i][j]+” “);
}
System.out.println(“|”);
}
}
if(pilih == 3){
JOptionPane.showMessageDialog(null, “PERKALIAN [x]”);
System.out.println(“3. PERKALIAN”);
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
for(int k=0;k<baris;k++){
C[i][j]=C[i][j]+(A[i][k]*B[k][j]);
}
System.out.print(” “+C[i][j]+” “);
}
System.out.println(“|”);
}
}
if(pilih == 4){
JOptionPane.showMessageDialog(null, “PEMBAGIAN”);
System.out.println(“4. PEMBAGIAN”);
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
C[i][j]=A[i][j]/B[i][j];
System.out.print(” “+C[i][j]+” “);
}
System.out.println(“|”);
}
}
if(pilih == 5){
JOptionPane.showMessageDialog(null, “TRANSPOSE”);
System.out.println(“5. TRANSPOSE”);
int opt=Integer.parseInt(JOptionPane.showInputDialog(“Hasil dari :” +”\n”
+ “1. Transpose Matrik A” + “\n”
+ “2. Transpose Matrik B” + “\n”
+ “3. Transpose Matrik C” + “\n”));
if(opt==1){
JOptionPane.showMessageDialog(null,”1. Transpose Matrik A”);
System.out.println(“Hasil dari Transpose Matrik A”);
for(int j=0;j<kolom;j++){
System.out.print(“|”);
for(int i=0;i<baris;i++){
System.out.print(” “+A[i][j]+” “);
}
System.out.println(“|”);
}
}
if(opt==2){
JOptionPane.showMessageDialog(null,”2. Transpose Matrik B”);
System.out.println(“Hasil dari Tranpose Matrik B”);
for(int j=0;j<kolom;j++){
System.out.print(“|”);
for(int i=0;i<baris;i++){
System.out.print(” “+B[i][j]);
}
System.out.println(“|”);
}
}
if(opt==3){
JOptionPane.showMessageDialog(null,”3. Transpose Matrik C”);
System.out.println(“Hasil dari Tranpose Matrik C”);
for(int j=0;j<kolom;j++){
System.out.print(“|”);
for(int i=0;i<baris;i++){
C[i][j]=A[i][j]+B[i][j];
System.out.print(” “+C[i][j]+” “);
}
System.out.println(“|”);
}
}
}
if(pilih == 6){
JOptionPane.showMessageDialog(null, “INVERS”);
System.out.println(“6. INVERS”);
int coba=Integer.parseInt(JOptionPane.showInputDialog(“Coba : ” + “\n”
+ “1. Matriks Biasa” + “\n”
+ “2. Matriks Bervariabel” + “\n”));
if(coba==1){
JOptionPane.showMessageDialog(null,”1. Matrik Biasa”);
System.out.println(“1. Matriks Biasa”);
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
C[i][j]=A[i][j]+B[i][j];
System.out.print(” “+C[i][j]+” “);
}
System.out.println(“|”);
}
System.out.println();
float dtr=C[0][0]*C[1][1]-C[0][1]*C[1][0];
System.out.println(“Determinannya : “+dtr);
float temp=C[0][0];
C[0][0]=C[1][1];
C[1][1]= (int) temp;
C[0][1]=C[0][1]*-1;
C[1][0]=C[1][0]*-1;
System.out.println(” “);
System.out.println(“Kofaktor”);
int [][]k = new int [3][3];
k[0][0]= 1*((C[1][1]*C[2][2])-(C[1][2]*C[2][1]));
k[0][1]= -1*((C[1][0]*C[2][1])-(C[1][2]*C[2][0]));
k[0][2]= 1*((C[1][0]*C[2][1])-(C[1][1]*C[2][0]));
k[1][0]= -1*((C[0][1]*C[2][2])-(C[0][2]*C[2][1]));
k[1][1]= 1*((C[0][0]*C[2][2])-(C[0][2]*C[2][0]));
k[1][2]= -1*((C[0][0]*C[2][1])-(C[0][1]*C[2][0]));
k[2][0]= 1*((C[0][1]*C[1][2])-(C[0][2]*C[1][1]));
k[2][1]= -1*((C[0][0]*C[1][2])-(C[0][2]*C[1][0]));
k[2][2]= 1*((C[0][0]*C[1][1])-(C[0][1]*C[1][0]));
for(int i=0;i<k.length;i++){
System.out.print(“|”);
for(int j=0;j<k.length;j++){
System.out.print(” “+k[i][j]);}
System.out.println(” | “);
}
System.out.println(” “);
System.out.println(“Invers Matriknya : “);
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
System.out.print(C[i][j]/dtr+” “);
}
System.out.println(“|”);
}
System.out.println(” “);
System.out.println(“Hasil dari Transpose [k] kofaktor”);
for(int j=0;j<kolom;j++){
System.out.print(“|”);
for(int i=0;i<baris;i++){
System.out.print(” “+k[i][j]+” “);
}
System.out.println(“|”);
}
}
if(coba==2){
JOptionPane.showMessageDialog(null, “2. Matriks bervariabel”);
System.out.println(“2. Matriks bervariabel”);
int var_A[][]=new int[3][3];
String var_xyz[]={“x”,”y”,”z”};
int var_B[]=new int[3];
int variabel[]=new int[var_xyz.length];

System.out.println(“Bentuk Matrik fungsi X”);
System.out.print(“x”+var_xyz[0]+” + “+”y”+var_xyz[1]+” + “+”z”+var_xyz[2]+” = “+var_xyz.length+”\n”+
“x”+var_xyz[0]+” + “+”y”+var_xyz[1]+” + “+”z”+var_xyz[2]+” = “+var_xyz.length+”\n”+
“x”+var_xyz[0]+” + “+”y”+var_xyz[1]+” + “+”z”+var_xyz[2]+” = “+var_xyz.length+”\n”+ “** sehingga menjadi **”+”\n”);
System.out.println(“——————————–“);
for(int i=0;i<A.length;i++){
for(int j=0;j<A.length;j++){
//  var_A[i][j]=Integer.parseInt(JOptionPane.showInputDialog(“Masukkan Matrik A” +(i+1)));
System.out.print(” + ” + (A[i][j]) + var_xyz[i]);
}
var_B[i]=Integer.parseInt(JOptionPane.showInputDialog(“Masukkan Matrik B”+(i+1)));
System.out.println(” = ” + var_B[i]);
}
System.out.println(“Perubahan ke bentuk Matrik”);
for(int i=0;i<3;i++){
System.out.print(“|”);
for(int j=0;j<3;j++){
System.out.print(” “+A[i][j]);
}
System.out.println(” |”+”\t”+”|”+var_xyz[i]+”|”+”\t”+”|”+var_B[i]+”|”);
}
System.out.println(”    A      “+”.”+”  x  “+” = “+”   B   “);
System.out.println(“\nA.X=B”);
System.out.println(“X=B/A”);
System.out.println(” “);
System.out.println(“Kofaktor”);
int [][]k = new int [3][3];
k[0][0]= 1*((A[1][1]*A[2][2])-(A[1][2]*A[2][1]));
k[0][1]= -1*((A[1][0]*A[2][1])-(A[1][2]*A[2][0]));
k[0][2]= 1*((A[1][0]*A[2][1])-(A[1][1]*A[2][0]));
k[1][0]= -1*((A[0][1]*A[2][2])-(A[0][2]*A[2][1]));
k[1][1]= 1*((A[0][0]*A[2][2])-(A[0][2]*A[2][0]));
k[1][2]= -1*((A[0][0]*A[2][1])-(A[0][1]*A[2][0]));
k[2][0]= 1*((A[0][1]*A[1][2])-(A[0][2]*A[1][1]));
k[2][1]= -1*((A[0][0]*A[1][2])-(A[0][2]*A[1][0]));
k[2][2]= 1*((A[0][0]*A[1][1])-(A[0][1]*A[1][0]));
for(int i=0;i<k.length;i++){
System.out.print(“|”);
for(int j=0;j<k.length;j++){
System.out.print(” “+k[i][j]);}
System.out.println(” | “);
}

}

}
if(pilih == 7){
JOptionPane.showMessageDialog(null, “CRAMMER”);
System.out.println(“7. CRAMMER”);
JOptionPane.showMessageDialog(null,”Metode CRAMMER”);
int cr[][]=new int[3][3];
int cra[] =new int[3];
String cramm[]={“x”,”y”,”z”};
int variabel[]=new int[cra.length];
System.out.println(“Bentuk dari Crammer yang mempunyai variabel : “);
System.out.println(“x”+cramm[0]+” + “+”y”+cramm[1]+” + “+”z”+cramm[2]+” = “+cramm.length+”\n”+
“x”+cramm[0]+” + “+”y”+cramm[1]+” + “+”z”+cramm[2]+” = “+cramm.length+”\n”+
“x”+cramm[0]+” + “+”y”+cramm[1]+” + “+”z”+cramm[2]+” = “+cramm.length+”\n”+ “** sehingga menjadi **”+”\n”);
System.out.println(“——————————–“);
for(int i=0;i<A.length;i++){
for(int j=0;j<A.length;j++){
//  var_A[i][j]=Integer.parseInt(JOptionPane.showInputDialog(“Masukkan Matrik A” +(i+1)));
System.out.print(” + ” + (A[i][j]) + cramm[i]);
}
cra[i]=Integer.parseInt(JOptionPane.showInputDialog(“Masukkan Matrik B”+(i+1)));
System.out.println(” = ” + cra[i]);
}
System.out.println(“Perubahan ke bentuk Matrik”);
for(int i=0;i<3;i++){
System.out.print(“|”);
for(int j=0;j<3;j++){
System.out.print(” “+A[i][j]);
}
System.out.println(” |”+”\t”+”|”+cramm[i]+”|”+”\t”+”|”+cra[i]+”|”);
}
System.out.println(”    A      “+”.”+”  x  “+” = “+”   B   “);
System.out.println();
float dtr=A[0][0]*A[1][1]-A[0][1]*A[1][0];
System.out.println(“Determinannya : “+dtr);
float temp=A[0][0];
A[0][0]=A[1][1];
A[1][1]= (int) temp;
A[0][1]=A[0][1]*-1;
A[1][0]=A[1][0]*-1;
System.out.println(” “);
int nilai =((A[0][0]*A[1][1]*A[2][2])+
(A[0][1]*A[1][2]*A[2][0])+
(A[0][2]*A[1][0]*A[2][1]))-
((A[0][1]*A[1][0]*A[2][2])+
(A[0][0]*A[1][2]*A[2][1])+
(A[0][2]*A[1][1]*A[2][0]));
System.out.println(“|A| : “+nilai);
System.out.println(“Perhitungan dari Determinan :”);

}
if(pilih == 8){
JOptionPane.showMessageDialog(null, “GAUSS”);
System.out.println(“8. GAUSS”);
int var_A[][]=new int [3][3];
int var_b[]  =new int [3];
String vari[]   ={“x”,”y”,”z”};
int ex[][]={{1,1,2},{2,4,-3},{3,6,-5}};
int contoh1[]={9,1,0};
for(int i=0;i<A.length;i++){
System.out.print(“|”);
for(int j=0;j<A.length;j++){
System.out.print(” “+ex[i][j]);
}
System.out.println(“|”+”\t”+”|”+vari[i]+”|”+”\t”+”|”+contoh1[i]+”|”);
}
System.out.println(”   A   “+””+”        “+”  X    “+” =  “+”   B   “);
System.out.println(“”);
System.out.println(“Perubahan baris ke-1”);
int [][]r = new int [3][3];
r[2][1]= ((ex[2][1])-2*ex[2][2]);
r[2][2]= ((ex[2][2])-2*ex[1][2]);
r[2][0]= (4-2*1);
r[2][1]= -1*((ex[0][0]*ex[1][2])-(ex[0][2]*ex[1][0]));
r[2][2]= 1*((ex[0][0]*ex[1][1])-(ex[0][1]*ex[1][0]));
for(int i=0;i<r.length;i++){
System.out.print(“|”);
for(int j=0;j<r.length;j++){
System.out.print(” “+r[i][j]);}
System.out.println(” | “);

}
}

if(pilih == 9){
JOptionPane.showMessageDialog(null, “DETERMINAN”);
System.out.println(“9. DETERMINAN”);
int opt=Integer.parseInt(JOptionPane.showInputDialog(“Hasil dari :” +”\n”
+ “1. Determinan Matrik A” + “\n”
+ “2. Determinan Matrik B” + “\n”
+ “3. Determinan Matrik C” + “\n”));
if(opt==1){
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
System.out.print(” “+A[i][j]+” “);
}
System.out.println(“|”);
}
int dtr=((A[0][0]*A[1][1]*A[2][2])+
(A[0][1]*A[1][2]*A[2][0])+
(A[0][2]*A[1][0]*A[2][1]))-
((A[0][1]*A[1][0]*A[2][2])+
(A[0][0]*A[1][2]*A[2][1])+
(A[0][2]*A[1][1]*A[2][0]));
JOptionPane.showMessageDialog(null, “Determinan : ” +dtr);
System.out.println(“Determinan : “+dtr);
}
if(opt==2){
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
System.out.print(” “+B[i][j]+” “);
}
System.out.println(“|”);
}
int dtr=((B[0][0]*B[1][1]*B[2][2])+
(B[0][1]*B[1][2]*B[2][0])+
(B[0][2]*B[1][0]*B[2][1]))-
((B[0][1]*B[1][0]*B[2][2])+
(B[0][0]*B[1][2]*B[2][1])+
(B[0][2]*B[1][1]*B[2][0]));
JOptionPane.showMessageDialog(null, “Determinan : ” +dtr);
System.out.println(“Determinan : “+dtr);
}
if(opt==3){
for(int i=0;i<baris;i++){
System.out.print(“|”);
for(int j=0;j<kolom;j++){
C[i][j]=A[i][j]+B[i][j];
System.out.print(” “+C[i][j]+” “);
}
System.out.println(“|”);
}
System.out.println(“\n” + “>> hasil dari Matrik C”);
int dtr=((C[0][0]*C[1][1]*C[2][2])+
(C[0][1]*C[1][2]*C[2][0])+
(C[0][2]*C[1][0]*C[2][1]))-
((C[0][1]*C[1][0]*C[2][2])+
(C[0][0]*C[1][2]*C[2][1])+
(C[0][2]*C[1][1]*C[2][0]));
JOptionPane.showMessageDialog(null, “Determinan : ” +dtr);
System.out.println(“Determinan : “+dtr);
}
}
if(pilih == 10){
JOptionPane.showMessageDialog(null, “Terima Kasih ^,^”);
System.out.println(“Terima kasih!!! ^_^”);
System.exit(0);
}
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s