2016-05-22 ~ neT-Tor.com

Tuesday 24 May 2016

Perkalian matrik vektor


A.# Identifikasi masalah

     mengalikan matrik ordo 3x2 dengan vector.

B.# Menentukan input dan output
     input   : matrik[2][3]={ 2,3,1,4,2,3}.
                    vektor[3]={ 3,4,2}.
     output : hasil[2].

C.# Membuat flowchart/ Algoritma
     Procedur kali matrik
vektor ( input/output e,k,matvek)
     Deklarasi 
     e,k, = integer
     Deskripsi
     for e<- 1 to 2 do
         for k<- 1 to 3 do
               ([e,k]=([e,k]+a[e,k]*b[e,k])
               end for
         end for
    end    
 
D.# C++
#include <iostream>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or        input loop */

void kali(int matrik[2][3],int vektor[3],int hasil[2]){
 cout<<"matrik -> = \n";
 for(int e=0;e<2;e++){
  for(int k=0;k<3;k++)
   hasil[e]=hasil[e]+(matrik[e][k]*vektor[k]);
 }
}
void cetakm(int hasil[][3]){
 for(int e=0;e<2;e++){
  for(int k=0;k<3;k++)
   cout<<hasil[e][k]<<" ";
   cout<<endl;
 }
}
void cetakv(int vektor[]){
 cout<<"vektor -> = \n";
 for(int e=0;e<3;e++){
  cout<<vektor[e]<<endl;
 }
}

void cetak(int hasil[]){
 cout<<"hasil -> = \n";
 for(int e=0;e<2;e++){
  cout<<hasil[e]<<endl;
 }
}
int main(int argc, char** argv) {
 int matrik[2][3]={2,3,1,4,2,3}, vektor[3]={3,4,2},hasil[2]={0};
 kali(matrik,vektor,hasil);
 cetakm(matrik);
 cetakv(vektor);
 cetak(hasil);
 return 0;

}
    
E.#. Menguji coba


F.#.Debugging program

MATRIK
    j=1  j=2  j=3

A i=1|   3      2     3
    i=2|  2      3     4

VEKTOR
           J=1
B i=1|  1  |
    i=2| 2  |
    i=3| 3  |
cara kerja (perkaalian)
C = |A11.B11+A12.B21+A13.B13|
       |A21.B11+A22.B21+A23.B31|
jadi
( dalam bentuk nilainya )
       | 1x1 + 3x2 + 3x3 |
       | 2x1 + 3x2 + 4x3 |
hasil
 nya
       | 14 |
       | 20 |

Begitulah hasil debugging program.