1. Identifikasi Masalah
=>Perkalian Matrik dengan Vektor
2. Menentukan Input dan Output
Input :
matrix [2] [3]: | 3 4 2 |
| 6 5 1 |
vektor [3] : | 3 |
| 0 |
| 1 |
Output :
Hasil perkalian matrix 2x3 dan vektor 3 elemen :
11
19
3. Membuat Flowchart atau Algoritma
Algoritma
Perkalian_Matrix
{ Menghitung hasil perkalian matrix elemen 2x3 dan
vektor(elemen 3)}
Deklarasi :
matrix [2] [3] = {3,4,2,6,5,1} :
integer
vektor [3] = {3,0,1} :
integer
hasil ={0} :
integer
Deskripsi :
Write('Matrik elemen
2x3 : \n')
for i ß
0 to 2 do then i++
for j ß 0 to 3 then j++
hasil[i] ß hasil[i]+(matrix[i][j]*vektor[j]);
end for
end for
for i ß 0 to 2 do then i++
for j ß
0 to 3 then j++ then
write(hasil[i][j])
end for
end for
write(‘Vektor 3 elemen:
\n’)
for j ß
0 to 3 then j++ then
write(vektor[i])
end
for
write(‘Hasil perkalian
matrix 2x3 dan vektor 3 elemen : \n’)
for i ß
0 to 2 then i++
write(hasil[i])
end
for
4. Implementasi C++
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void perkalian(int matrix[2][3],int vektor[3],int hasil[2]){
cout<<"Matrik elemen 2x3 : \n";
for(int i=0;i<2;i++){
for(int j=0;j<3;j++)
hasil[i]=hasil[i]+(matrix[i][j]*vektor[j]);
}
}
void cetakmatrix(int hasil[][3]){
for(int i=0;i<2;i++){
for(int j=0;j<3;j++)
cout<<hasil[i][j]<<" ";
cout<<endl;
}
}
void cetakvektor(int vektor[]){
cout<<"Vektor 3 elemen: \n";
for(int i=0;i<3;i++){
cout<<vektor[i]<<endl;
}
}
void cetak(int hasil[]){
cout<<"Hasil perkalian matrix 2x3 dan vektor 3 elemen : \n";
for(int i=0;i<2;i++){
cout<<hasil[i]<<endl;
}
}
int main(int argc, char** argv) {
int matrix[2][3]={3,4,2,6,5,1}, vektor[3]={3,0,1},vek[2]={2,10},hasil[2]={0};
perkalian(matrix,vektor,hasil);
cetakmatrix(matrix);
cetakvektor(vektor);
cetak(hasil);
return 0;
}
5. Test Menggunakan Data
Input :
matrix [2] [3]: | 3 4 2 |
| 6 5 1 |
vektor [3] : | 3 |
| 0 |
| 1 |
Output :
Hasil perkalian matrix 2x3 dan vektor 3 elemen :
11
19
6. Eksekusi
Comments
Post a Comment