1.
Identifikasi Masalah
Cara Mengalikan matrik 3x2 dengan vektor.
2. Menentukan
input dan output
input : Matrik = | 2 1 4 |
| 1 4 2 |
Vektor = | 1 |
| 2 |
| 4 |
output : hasil = | 20 |
| 17 |
3.
Algoritma
Procedur kali matrik (input/output i,j,matrik vektor
Deskripsi :
for i<- 1 to 2 do
for j<- 1 to 3 do
([i,j]=(i,j)+a[i,j]*b[i,j])
end for
end for
end for
4.
Mengimplementasikan dengan 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 i=0;i<2;i++){
for(int j=0;j<3;j++)
hasil[i]=hasil[i]+(matrik[i][j]*vektor[j]);
}
}
void cetakm(int hasil[][3]){
for(int i=0;i<2;i++){
for(int j=0;j<3;j++)
cout<<hasil[i][j]<<" ";
cout<<endl;
}
}
void cetakv(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]={2,1,4,1,4,2}, vektor[3]={1,2,4},hasil[2]={0};
kali(matrik,vektor,hasil);
cetakm(matrik);
cetakv(vektor);
cetak(hasil);
return 0;
}
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 i=0;i<2;i++){
for(int j=0;j<3;j++)
hasil[i]=hasil[i]+(matrik[i][j]*vektor[j]);
}
}
void cetakm(int hasil[][3]){
for(int i=0;i<2;i++){
for(int j=0;j<3;j++)
cout<<hasil[i][j]<<" ";
cout<<endl;
}
}
void cetakv(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]={2,1,4,1,4,2}, vektor[3]={1,2,4},hasil[2]={0};
kali(matrik,vektor,hasil);
cetakm(matrik);
cetakv(vektor);
cetak(hasil);
return 0;
}
5. Output
6. Uji
coba dengan data
Matrik
A = | 2 1 4 |
| 1 4 2 |
Vektor
B = | 1 |
| 2 |
| 4 |
Perkalian
C = |A11.B11+A12.B21+A13.B13|
|A21.B11+A22.B21+A23.B31|
= | 1x1 + 3x2 + 3x3 |
| 2x1 + 3x2 + 4x3 |
Hasil
| 20 |
| 17 |
Tidak ada komentar:
Posting Komentar