Perkalian 2 Matriks Menggunakan Netbeans
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Ngerjakan_Ulang_Soal_UTS;
/**
*
* @author Al-Fattah
*/
public class Soal1_Buat_Perkalian_Matriks {
public static void main(String[] args){
int [][] A={{1,2},{3,4}};
int [][] B={{4,5},{6,7}};
int [][] C= new int[2][2];
int i,ii;
int [][]X= {{(A [0] [0] * B [0] [0]),
(A[0][0]*B[0][1])},
{(A[1][0]*B[0][0]),
(A[1][0]*B[0][1])}};
int [][]Y= {{(A[0][1]*B[1][0]),
(A[0][1]*B[1][0])},
{(A[1][1]*B[1][0]),
(A[1][1]*B[1][1])}};
for (i=0; i<2; i++){
for(ii=0; ii<2; ii++)
C[i][ii]=X [i][ii] + Y [i] [ii];
}
for (i=0; i<2; i++){
for (ii=0; ii<2; ii++){
System.out.printf("%3d",C[i] [ii]);
}
System.out.println();
}
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Ngerjakan_Ulang_Soal_UTS;
/**
*
* @author Al-Fattah
*/
public class Soal1_Buat_Perkalian_Matriks {
public static void main(String[] args){
int [][] A={{1,2},{3,4}};
int [][] B={{4,5},{6,7}};
int [][] C= new int[2][2];
int i,ii;
int [][]X= {{(A [0] [0] * B [0] [0]),
(A[0][0]*B[0][1])},
{(A[1][0]*B[0][0]),
(A[1][0]*B[0][1])}};
int [][]Y= {{(A[0][1]*B[1][0]),
(A[0][1]*B[1][0])},
{(A[1][1]*B[1][0]),
(A[1][1]*B[1][1])}};
for (i=0; i<2; i++){
for(ii=0; ii<2; ii++)
C[i][ii]=X [i][ii] + Y [i] [ii];
}
for (i=0; i<2; i++){
for (ii=0; ii<2; ii++){
System.out.printf("%3d",C[i] [ii]);
}
System.out.println();
}
}
}
Komentar
Posting Komentar