Mengerti masalah
Mengalikan matrik (3x2) dengan vektor (3).
Menentukan input dan output
input : A[2,3]={4,2,1,0,1,3}
B [3]={1,1,3}
Mengalikan matrik (3x2) dengan vektor (3).
Menentukan input dan output
input : A[2,3]={4,2,1,0,1,3}
B [3]={1,1,3}
output : C |8|
|6|
Membuat Algoritma
Prosedur kali matrik ( input/output i,j,A,B)
# Deklarasi
i,j, = integer
# 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
Membuat Algoritma
Prosedur kali matrik ( input/output i,j,A,B)
# Deklarasi
i,j, = integer
# 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
Mengimplementasikan ke DevC++
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
void kali(int A2][3],int B[3],int C[2]){
cout<<"matrik : "<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<3;j++)
C[i]=hC[i]+(A[i][j]*B[j]);
}
}
void matrik(int C[][3]){
for(int i=0;i<2;i++){
for(int j=0;j<3;j++)
cout<<hasil[i][j]<<" "<<endl;
}
}
void vektor(int B[]){
cout<<"vektor : \n";
for(int i=0;i<3;i++){
cout<<vektor[i]<<endl;
}
}
void hasil(int C[]){
cout<<"hasil trakhir : "<<endl;
for(int i=0;i<2;i++){
cout<<C[i]<<endl;
}
}
int main(int argc, char** argv) {
int A[2][3]={4,2,1,0,1,3}, B[3]={1,1,2}, C[2]={0};
cout<<"matrik : "<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<3;j++)
C[i]=hC[i]+(A[i][j]*B[j]);
}
}
void matrik(int C[][3]){
for(int i=0;i<2;i++){
for(int j=0;j<3;j++)
cout<<hasil[i][j]<<" "<<endl;
}
}
void vektor(int B[]){
cout<<"vektor : \n";
for(int i=0;i<3;i++){
cout<<vektor[i]<<endl;
}
}
void hasil(int C[]){
cout<<"hasil trakhir : "<<endl;
for(int i=0;i<2;i++){
cout<<C[i]<<endl;
}
}
int main(int argc, char** argv) {
int A[2][3]={4,2,1,0,1,3}, B[3]={1,1,2}, C[2]={0};
kali(A,B,C);
matrik(A);
vektor(B);
hasil(C);
return 0;
}
Menguji coba program
data berhasil berjalan.
Test menggunakan data
Matrik: j=1 j=2 j=3
A i=1 | 4 2 1 | i=2 | 0 1 3 |
A i=1 | 4 2 1 | i=2 | 0 1 3 |
vektor:B i=1 | 1 |
i=2 | 1 |
i=3 | 2 |
perkaliannya: C = |A11.B11+A12.B21+A13.B31|
|A21.B11+A22.B21+A23.B31|
= | 4+2+2 |
| 0+1+6|
= | 8 |
| 6 |
|A21.B11+A22.B21+A23.B31|
= | 4+2+2 |
| 0+1+6|
= | 8 |
| 6 |
0 komentar:
Posting Komentar