1.Identifikasi masalah:
Mengkalikan vektor 2 elemen,3 elemen dan matrix 2x3
2.Menentukan Input dan Output
Input:
Matrix [2][3]={9,7,5,2,8,3}
Vektor [3]={5,2,6}
vek [2]={4,2}
Output:
Matrix 2x3 dan Vektor 3 elemen
89
44
vek lemen 2 dengan Matrix 2x3 dan Vektor elemen 3
356
88
3. Membuat Flowcart atau Algoritma
Deklarasai :
Matrix[2][3]={9,7,5,2,8,3} = integer
Vektor [3]={5,2,6} = integer
vek[2]={4,2} = integer
hasil[2]=0= integer
Deskrpsi :
write('MATRIX ELEMEN 2X3 : \n')
for i ß 0 to 2 do then a++
for j ß 0 to 3 then j++
hasil[a] ß hasil[a]+(matrix[a][b]*vektor[b]);
end for end for
for a ß 0 to 2 do then a++
for b ß 0 to 3 then b++ then
write(hasil[a][b])
end for end for
write(‘VEKTOR 3 ELEMEN: \n’)
for b ß 0 to 3 then b++ then
write(vektor[a]) end for
write(‘VEKTOR 2 ELEMEN : \n’)
for a ß 0 to 2 then a++ then
write(vek[a]) end for
write(‘HASIL MATRIX 2X3 DAN VEKTOR 3 ELEMEN : \n’)
for a ß 0 to 2 then a++
write(hasil[a]) end for
write(‘HASIL VEKTOR 2 ELEMEN DENGAN MATIRIX ELEMEN 2X3 DAN VEKTOR 3 ELEMEN : \n’)
for a ß 0 to 2 then a++
hasil[i] ßhasil[a]*vek[a];
write(hasil[a]) end for
4. Test Menggunakan Data
Input :
matrix [2] [3] : | 9 7 5 |
| 2 8 3 |
vektor [3] : | 5 |
| 2 |
| 6 |
vek [2] | 4 |
| 2 |
Output :
Hasil kali Matrix 2x3 dan Vektor 3 elemen : 89
44
Hasil akhir : 356
88
5. 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 cetakb(int vek[]){
cout<<"Vektor 2 elemen : \n";
for(int i=0;i<2;i++){
cout<<vek[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;
}
}
void cetaka(int vek[2],int hasil[]){
cout<<"Hasil perkalian vektor(elemen 2) dengan matrix elemen 2x3 dan vektor(elemen 3) : \n";
for(int i=0;i<2;i++){
hasil[i]=hasil[i]*vek[i];
cout<<hasil[i]<<endl;
}
}
int main(int argc, char** argv) {
int Matrix[2][3]={9,7,5,2,8,3}, Vektor[3]={5,2,6},vek[2]={4,2},hasil[2]={0};
perkalian(matrix,vektor,hasil);
cetakmatrix(matrix);
cetakvektor(vektor);
cetak(hasil);
cetakb(vek);
cetaka(vek,hasil);
return 0;
}