Matrix multiplication have error
11 views (last 30 days)
Show older comments
Hi guys.
I want to multiply this matrix in matlab. But, I have error in matlab which is "inner matrix dimension must agree". My matrix A is A = [1; 2; 3; 4]. While matrix B is B = [1 2 3 4 5 6 7; 8 9 10 11 12 13 14; 15 16 17 18 19 20 21]. How can I multiply this matrix in matlab. Kindly help me please.
1 Comment
Star Strider
on 7 May 2015
You can’t multiply them. They have to have at least one dimension in common, and A is (4x1) and B is (3x7).
Answers (2)
Walter Roberson
on 7 May 2015
It is not possible to do matrix multiplication between a matrix of size 3 x 7, and a vector of length 1 x 4. In order to do matrix multiplication C * D, the second dimension of C (number of rows) must be the same as the first dimension of D (number of columns). The "1" of the vector does not match either 3 or 7, and the "4" of the vector does not match either 3 or 7, so there is no combination of switching positions or transposing that can be used to do matrix multiplication between the two.
If your vector A were length 3 instead of 4, then A * B would not work because (3 x 1) * (3 x 7) does not have the second dimension of the first, 1, match the 3. Likewise B * A would not work because (3 x 7) * (3 x 1) would not have the 7 match the 3. But, A' * B where the ' indicates transposition, would be (1 x 3) * (3 x 7) and so could execute, producing 1 x 7;and B' * A = (7 x 3) * (3 x 1) could execute, producing 7 x 1.
0 Comments
Purushottama Rao
on 7 May 2015
Pls refer the basic matrix multiplication rules. you can not multiply a 4*1 matirx with 3*7 matrix.
1 Comment
Purushottama Rao
on 7 May 2015
If u want to multiply matrices, inner dimensions should match. EX: you can multiply a matrix of size 3*4 with 4*8 since the inner dimenstion (4) matches. THIS OPERATION RESULTS IN A 3*8 MATRIX
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!