60 likes | 217 Views
ADT MATRIK. ADT Matrik. Class Rep ADT Matrik. Refresentasi ADT Matrik. double []A = {3,4,1,10,5,2,10,20,16}; double []B = {4,3,1,11,7}; Larik L1 = new Larik (A); Larik L2 = new Larik (B); Matrik A,B,C; double [][]data1 = {{1,2,3},{3,4,7}}; double [][]data2 = {{4,5,1},{6,1,9}};
E N D
ADT Matrik • Class Rep ADT Matrik • Refresentasi ADT Matrik
double []A = {3,4,1,10,5,2,10,20,16}; double []B = {4,3,1,11,7}; Larik L1 = new Larik(A); Larik L2 = new Larik(B); • Matrik A,B,C; • double [][]data1 = {{1,2,3},{3,4,7}}; • double [][]data2 = {{4,5,1},{6,1,9}}; • A = new Matrik(data1); • B = new Matrik(data2);
Constructor Matrik /** * constructor untukmembuatsuatumatrikdari array 2 dimensi * @param A : array duadimensi */ public Matrik(double [][]A){ this.nBaris = A.length; this.nKolom = A[0].length; itemDt = new int [this.nBaris][this.nKolom]; for (inti=0; i<nBaris; i++){ for (int j=0; j<nKolom; j++){ this.itemDt[i][j] = A[i][j]; } } }
Matrik.tambah /** * fungsitambahantaraduamatrik A dan B * @param A : Matrik * @param B : Matrik * @return Matrikhasil */ public static Matriktambah(Matrik A, Matrik B){ Matrik C = null; int b1, b2, k1, k2; b1 = A.getNBaris(); b2 = B.getNBaris(); k1 = A.getNKolom(); k2 = B.getNKolom(); if ((b1 == b2) && (k1 == k2)){ C = new Matrik(b1,k1); for (int i=0; i<b1; i++){ for (int j=0; j<k1; j++){ double hasilTambah = A.getItem(i, j)+B.getItem(i, j); C.setItem(i,j, hasilTambah); } } } return C; } tambah
Tugas (kelompok) • Buatlah ADT representasiMatrik (array 2 dimensi) menjadi array 1 dimensi. • Tambahkanoperasidasarpada ADT tersebutmeliputi : • Constructor dasar • Constructor konversi array 2 dimensikestrukturmatrik • Cetak data matrik • Ambilvektorbarispadabaristertentu • Ambillvektorkolompadakolomtertentu • Penjumlahanantaraduabuahmatrik • Tranposmatrik • Perkalianantaravektordenganmatrik • Perkalianantaramatrikdenganmatrik