Matrix multiplication have error

2 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2015-5-7
You can’t multiply them. They have to have at least one dimension in common, and A is (4x1) and B is (3x7).

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2015-5-7
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.

Purushottama Rao
Purushottama Rao 2015-5-7
Pls refer the basic matrix multiplication rules. you can not multiply a 4*1 matirx with 3*7 matrix.
  1 个评论
Purushottama Rao
Purushottama Rao 2015-5-7
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by