Gerakan Digital

Selasa, 24 Mei 2016

Perkalian matrik dengan vektor menggunakan 6 kaidah

Assalamu'alaikum wr.wb
Halo pengunjung setia cyberclaza kali ini kita akan membahas tentang bagaimana penentuan hasil perkalian antara matrik x vektor (3x2) menggunakan 6 kaidah penyusunan program:



-Mengerti masalah

1.Mengalikan antara matrik dan vektor

2.menentukan input dan output

input : matrik[2][3]={1,3,4,6,5,4}
vektor[3]={3,1,2}
output : hasil[2]

3.Membuat algoritma

Deklarasi : i,j, = integer

Deskripsi : for (i=1 ; i<=2 ;i++)
for (j= 1 ; j<=3 ; j++
total [i][j]=0;
for (k= 1 ; k<=3 ; k++)
total [i][j] = total [i][j]+A[i][k][j] ;

4. Mencoba dengan data :

MATRIK
j=3 j=1 j=2
A i=1|134
i=2| 654
VEKTOR
J=1
B i=3| 3 |
i=1| 1 |
i=2| 2 |
cara perkalian
C = |A11*B11+A12*B21+A13*B31|
|A21*B11+A22*B21+A23*B31|
jadi
| 1x3 + 3x1 + 4x2 |
| 6x3 + 5x1 + 4x2 |
hasil akhirnya
| 14 |
| 31 |

5.CODINGAN DEV C++ :

#include <iostream>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void x(int matrik[2][3],int vektor[3],int hasil[2]){
cout<<"matrik : \n";
for(int i=0;i<2;i++){
for(int j=0;j<3;j++)
hasil[i]=hasil[i]+(matrik[i][j]*vektor[j]);
}
}
void cetmat(int hasil[][3]){
for(int i=0;i<2;i++){
for(int j=0;j<3;j++)
cout<<hasil[i][j]<<" ";
cout<<endl;
}
}
void cetvek(int vektor[]){
cout<<"vektor : \n";
for(int i=0;i<3;i++){
cout<<vektor[i]<<endl;
}
}

void cetak(int hasil[]){
cout<<"hasil trakhir : \n";
for(int i=0;i<2;i++){
cout<<hasil[i]<<endl;
}
}
int main(int argc, char** argv) {
int matrik[2][3]={ 1,3,4,6,5,4}, vektor[3]={3,1,2},hasil[2]={0};
x(matrik,vektor,hasil);
cetmat(matrik);
cetvek(vektor);
cetak(hasil);
return 0;

}


6. Hasil Outputnya nya :

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5TiqrrfccyPwjcOPAiG8P2aPExfw8RneMy9ooqvMe_MuKWO27ZKMrLH4UsNRsu0B_WvRke3FLhi-dmBhwOtbGYfcXwNXdFYY4H3wFXB0iccWk9jFamt2J4uBgC_saVG3h87ggIOlsL54/s320/ScreenShot_20160524202238.png





Tidak ada komentar:

Posting Komentar

Translate

Popular Posts

Postingan Populer

Recent Posts