Monday, June 20, 2016

LA MATIF Pertemuan 4

>>>>> DOWNLOAD .DOC <<<<<


LAPORAN AKHIR PRAKTIKUM

Nama Praktikum         : Matematika Informatika
Kelas                          : 1IA20
Praktikum ke              : 4
Tanggal                       : 4 Mei 2015
Materi                          : MATRIKS INVERS
NPM                           : 53414057
Nama                           : Didi Mulyadi
Ketua Asisten             : Bayu
Nama Asisten              :
Paraf Asisten               :
Jumlah Lembar            : 11 Lembar





Logo.jpg

LABORATORIUM INFORMATIKA
UNIVERSITAS GUNADARMA
2015

Listing Program
import java.util.*;

class InversMatriks{
            Scanner input = new Scanner(System.in);

            public void ordox(){
                        System.out.println("Ordo Matriks = 2X2");
                        int [][] matrik = new int [2][2];
                        int temp;
                       
                        System.out.println("\nMasukan Elemen Matriksnya:\n");
                        for(int i=0;i<2;i++){
                                    for(int j=0;j<2;j++){
                                                System.out.print("Elemen ["+(i+1)+","+(j+1)+"] = ");
                                                matrik[i][j]=input.nextInt();
                                                }
                                    }
                                   
                        System.out.println();
                       
                        for(int i=0;i<2;i++){
                                    System.out.print("|");
                                    for(int j=0;j<2;j++){
                                                System.out.print(" "+matrik[i][j]+" ");
                                                }
                                    System.out.println("|");
                                    }
                        System.out.println();
                       
                        float dtre=(matrik[0][0] * matrik[1][1]) - (matrik[0][1] * matrik[1][0]);
                        System.out.println("Determinannya="+dtre);
                        System.out.println();
                        System.out.println("Invers Matriks : ");
                       
                        temp = matrik[0][0];
                        matrik[0][0]=matrik[1][1];
                        matrik[1][1]=temp;
                        matrik[0][1]=matrik[0][1]*-1;
                        matrik[1][0]=matrik[1][0]*-1;
                       
                        for(int i=0;i<2;i++){
                                    System.out.print("|");
                                    for(int j=0;j<2;j++){
                                                System.out.print(" "+matrik[i][j]/dtre+" ");
                                                }
                                    System.out.println("|");
                                    }
                                   
            }

            public void ordoxx(){
                        System.out.println("Ordo Matriks = 3X3");
                        int [][] matrika = new int [3][3];

                        System.out.println("\nMasukan Elemen Matriksnya:\n");
                        for(int i=0;i<3;i++){
                                    for(int j=0;j<3;j++){
                                                System.out.print("Elemen ["+(i+1)+","+(j+1)+"] = ");
                                                matrika[i][j]=input.nextInt();
                                                }
                                    }
                                   
                                    System.out.println();
                                    for(int i=0;i<3;i++){
                                                System.out.print("|");
                                                for(int j=0;j<3;j++){
                                                            System.out.print(" "+matrika[i][j]+" ");
                                                            }
                                                System.out.println("|");
                                    }          
                                   
                                    //Cari nilai determinan
                                    float dtr=((matrika[0][0]*matrika[1][1]*matrika[2][2])+
                                                             (matrika[0][1]*matrika[1][2]*matrika[2][0])+
                                                             (matrika[0][2]*matrika[1][0]*matrika[2][1]))
                                                             -((matrika[0][2]*matrika[1][1]*matrika[2][0])+
                                                             (matrika[0][0]*matrika[1][2]*matrika[2][1])+
                                                             (matrika[0][1]*matrika[1][0]*matrika[2][2]));
                                    System.out.println("Determinannya="+dtr);
                                    System.out.println();
                                    System.out.println("Invers Matriks : ");
                                    System.out.println();
           
                                    //Proses Kofaktor
                                    int m11, m12, m13, m21, m22, m23, m31, m32, m33;
            m11 = (matrika[1][1]*matrika[2][2]-matrika[1][2]*matrika[2][1]);
            m12 = -1*(matrika[1][0]*matrika[2][2]-matrika[1][2]*matrika[2][0]);
            m13 = (matrika[1][0]*matrika[2][1]-matrika[1][1]*matrika[2][0]);
            m21 = -1*(matrika[0][1]*matrika[2][2]-matrika[0][2]*matrika[2][1]);
            m22 = (matrika[0][0]*matrika[2][2]-matrika[0][2]*matrika[2][0]);
            m23 = -1*(matrika[0][0]*matrika[2][1]-matrika[0][1]*matrika[2][0]);
            m31 = (matrika[0][1]*matrika[1][2]-matrika[0][2]*matrika[1][1]);
            m32 = -1*(matrika[0][0]*matrika[1][2]-matrika[0][2]*matrika[1][0]);
            m33 = (matrika[0][0]*matrika[1][1]-matrika[0][1]*matrika[1][0]);

            //Proses Adjoin (Transpose dariKofaktor)
                                    matrika[0][0] = m11;
                                    matrika[0][1] = m21;
                                    matrika[0][2] = m31;
                                    matrika[1][0] = m12;
                                    matrika[1][1] = m22;
                                    matrika[1][2] = m32;
                                    matrika[2][0] = m13;
                                    matrika[2][1] = m23;
                                    matrika[2][2] = m33;
                                   
                                    for(int i=0;i<3;i++){
                                    System.out.print("|");
                                    for(int j=0;j<3;j++){
                                                System.out.print(" "+matrika[i][j]/dtr+" ");
                                                }
                                    System.out.println("|");
                                    }
                        }


            public void menu(){
                        System.out.println();
                        System.out.println("================================");
                        System.out.println(" MENU PILIHAN ");
                        System.out.println(" 1. Ordo 2X2 ");
                        System.out.println(" 2. Ordo 3X3 ");
                        System.out.println(" 3. Keluar ");
                        System.out.println("================================");
                        System.out.println();
                        System.out.print("Masukkan Pilihan Anda : ");
                        int pil = input.nextInt();
                        System.out.println();
                       
                        if(pil==1){
                                    ordox();
                                    menu();
                        }
                       
                        if(pil==2){
                                    ordoxx();
                                    menu();
                        }

                        if(pil==3){
                                    System.out.println();
                                    System.out.println("Anda Telah Keluar");
                        }
            }

            public static void main(String[] args){
                        InversMatriks x = new InversMatriks();
                        x.menu();
            }

}


Logika Program
import java.util.*;

class InversMatriks{
            Scanner input = new Scanner(System.in);
           
Pada blok program  diatas digunakan untuk mengambil package scanner pada library java dan terdapat class dengan nama InversMatriks yang merupakan kelas utama . Scanner input = new Scanner(System.in); adalah sebuah instansiasi variable input , variable yang bernama input tersebut digunakan untuk mengambil inputan dari user.

            public void ordox(){
                        System.out.println("Ordo Matriks = 2X2");
                        int [][] matrik = new int [2][2];
                        int temp;
                       
                        System.out.println("\nMasukan Elemen Matriksnya:\n");
                        for(int i=0;i<2;i++){
                                    for(int j=0;j<2;j++){
                                                System.out.print("Elemen ["+(i+1)+","+(j+1)+"] = ");
                                                matrik[i][j]=input.nextInt();
                                                }
                                    }
                                   
                        System.out.println();
                       
                        for(int i=0;i<2;i++){
                                    System.out.print("|");
                                    for(int j=0;j<2;j++){
                                                System.out.print(" "+matrik[i][j]+" ");
                                                }
                                    System.out.println("|");
                                    }
                        System.out.println();
                       
                        float dtre=(matrik[0][0] * matrik[1][1]) - (matrik[0][1] * matrik[1][0]);
                        System.out.println("Determinannya="+dtre);
                        System.out.println();
                        System.out.println("Invers Matriks : ");
                       
                        temp = matrik[0][0];
                        matrik[0][0]=matrik[1][1];
                        matrik[1][1]=temp;
                        matrik[0][1]=matrik[0][1]*-1;
                        matrik[1][0]=matrik[1][0]*-1;
                       
                        for(int i=0;i<2;i++){
                                    System.out.print("|");
                                    for(int j=0;j<2;j++){
                                                System.out.print(" "+matrik[i][j]/dtre+" ");
                                                }
                                    System.out.println("|");
                                    }                      
            }
     
Pada blok program diatas digunakan  untuk menghitung determinan matriks 2x2. Kemudian pada System.out.println("\nMasukan Elemen Matriksnya:"); digunakan untuk mencetak “masukan element matriknya:” diikuti dengan perintah inputan di statement berikutnya,lalu terdapat for(int i=0;i<2;i++){ & for(int j=0;j<2;j++){ yang digunakan pada output System.out.print("Elemen ["+(i+1)+","+(j+1)+"]="); dan  pada variabel i dan j dimulai dari nol sampai satu dan pada output akan ditambah satu. Kemudian |matrik[0][0] matrik[0][1]|digunakan untuk menghitung detrminan pada matriks yang telah diinput oleh user tadi, dengan cara (matrik[0][0] * matrik[1][1]) - (matrik[0][1] * matrik[1][0]).Kemudian  pada blok program  ini juga terdapat perintah  operasi menhitung nilai invers matriks 2x2 yang telah diinput oleh user. Dengan 1 per satu hasil determinan dikali dengan adjoin dari nilai matriks yang telah diinput oleh user.

            public void ordoxx(){
                        System.out.println("Ordo Matriks = 3X3");
                        int [][] matrika = new int [3][3];

                        System.out.println("\nMasukan Elemen Matriksnya:\n");
                        for(int i=0;i<3;i++){
                                    for(int j=0;j<3;j++){
                                                System.out.print("Elemen ["+(i+1)+","+(j+1)+"] = ");
                                                matrika[i][j]=input.nextInt();
                                                }
                                    }
                                   
                                    System.out.println();
                                    for(int i=0;i<3;i++){
                                                System.out.print("|");
                                                for(int j=0;j<3;j++){
                                                            System.out.print(" "+matrika[i][j]+" ");
                                                            }
                                                System.out.println("|");
                                    }          
                                   
                                    //Cari nilai determinan
                                    float dtr=((matrika[0][0]*matrika[1][1]*matrika[2][2])+
                                                             (matrika[0][1]*matrika[1][2]*matrika[2][0])+
                                                             (matrika[0][2]*matrika[1][0]*matrika[2][1]))
                                                             -((matrika[0][2]*matrika[1][1]*matrika[2][0])+
                                                             (matrika[0][0]*matrika[1][2]*matrika[2][1])+
                                                             (matrika[0][1]*matrika[1][0]*matrika[2][2]));
                                    System.out.println("Determinannya="+dtr);
                                    System.out.println();
                                    System.out.println("Invers Matriks : ");
                                    System.out.println();
           
                                    //Proses Kofaktor
                                    int m11, m12, m13, m21, m22, m23, m31, m32, m33;
            m11 = (matrika[1][1]*matrika[2][2]-matrika[1][2]*matrika[2][1]);
            m12 = -1*(matrika[1][0]*matrika[2][2]-matrika[1][2]*matrika[2][0]);
            m13 = (matrika[1][0]*matrika[2][1]-matrika[1][1]*matrika[2][0]);
            m21 = -1*(matrika[0][1]*matrika[2][2]-matrika[0][2]*matrika[2][1]);
            m22 = (matrika[0][0]*matrika[2][2]-matrika[0][2]*matrika[2][0]);
            m23 = -1*(matrika[0][0]*matrika[2][1]-matrika[0][1]*matrika[2][0]);
            m31 = (matrika[0][1]*matrika[1][2]-matrika[0][2]*matrika[1][1]);
            m32 = -1*(matrika[0][0]*matrika[1][2]-matrika[0][2]*matrika[1][0]);
            m33 = (matrika[0][0]*matrika[1][1]-matrika[0][1]*matrika[1][0]);

            //Proses Adjoin (Transpose dariKofaktor)
                                    matrika[0][0] = m11;
                                    matrika[0][1] = m21;
                                    matrika[0][2] = m31;
                                    matrika[1][0] = m12;
                                    matrika[1][1] = m22;
                                    matrika[1][2] = m32;
                                    matrika[2][0] = m13;
                                    matrika[2][1] = m23;
                                    matrika[2][2] = m33;
                                   
                                    for(int i=0;i<3;i++){
                                    System.out.print("|");
                                    for(int j=0;j<3;j++){
                                                System.out.print(" "+matrika[i][j]/dtr+" ");
                                                }
                                    System.out.println("|");
                                    }
                        }

                 
Pada blok program diatas digunakan untuk menghitung determinan matriks 3x3. sama seperti logika diatas hanya saja ini menggunakan ordo 3x3 sehingga kondisi perulangan nya akan berhenti jika j<3 di mulai dari j=0.
|matrika[0][0] matrika[0][1] matrika[0][2]|
|matrika[1][0] matrika[1][1] matrika[1][2]|
|matrika[2][0] matrika[2][1] matrika[2][2]|
 digunakan untuk menghitung ordo 3x3 dengan cara ((matrika[0][0]*matrika[1][1]*matrika[2][2])+(matrika[0][1]*matrika[1][2]*matrika[2][0])+(matrika[0][2]*matrika[1][0]*matrika[2][1]))-((matrika[0][2]*matrika[1][1]*matrika[2][0])+(matrika[0][0]*matrika[1][2]*matrika[2][1])+(matrika[0][1]*matrika[1][0]*matrika[2][2]));. kemudian pada blok program diatas terdapat operasi menhitung nilai invers dari nilai matriks 3x3 dalam metode kofaktor dan metode adjoin. Dengan 1 per satu dari hasil determinan dikali dengan adjoin dari nilai matriks yang telah diinput oleh user.

            public void menu(){
                        System.out.println();
                        System.out.println("================================");
                        System.out.println(" MENU PILIHAN ");
                        System.out.println(" 1. Ordo 2X2 ");
                        System.out.println(" 2. Ordo 3X3 ");
                        System.out.println(" 3. Keluar ");
                        System.out.println("================================");
                        System.out.println();
                        System.out.print("Masukkan Pilihan Anda : ");
                        int pil = input.nextInt();
                        System.out.println();
                       
                        if(pil==1){
                                    ordox();
                                    menu();
                        }
                       
                        if(pil==2){
                                    ordoxx();
                                    menu();
                        }

                        if(pil==3){
                                    System.out.println();
                                    System.out.println("Anda Telah Keluar");
                        }
            }

           
Pada blok program diatas digunakkan untuk membuat menu dengan menggunakan perintah system.out.println kemudian pada menu ini menggunakan statemen percabangan if dengan kondisi dimana jika nilai dari variabel pil =1 maka program akan  mengeksekusi mthod ordox dan kembali ke method menu, jika pil=2 maka program akan mengeksekusi method ordoxx dan kembali ke method menu . kemudian jika pil = 3 maka akan tercetak anda telah keluar dan program telah selesai.

            public static void main(String[] args){
                        InversMatriks x = new InversMatriks();
                        x.menu();
            }

}

Pada blok program diatas digunakan  untuk memanggil data dari sub method pada blok program diatas di mulai dengan memanggil  method menu/mengeksekusi method menu.






Output Program

No comments:

Post a Comment

Entri yang Diunggulkan

Mengukur Kehandalan Web Hosting dari Sisi Uptime dan Downtime

Untuk menjalakan semua itu diperlukan kehandalan dari sisi server dan sumber daya manusia pengelola web hosting namun secara umum untuk dap...