Azzera filtri
Azzera filtri

Matrix multiplication have error

2 visualizzazioni (ultimi 30 giorni)
Maximum
Maximum il 7 Mag 2015
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 Commento
Star Strider
Star Strider il 7 Mag 2015
You can’t multiply them. They have to have at least one dimension in common, and A is (4x1) and B is (3x7).

Accedi per commentare.

Risposte (2)

Walter Roberson
Walter Roberson il 7 Mag 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.

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

Accedi per commentare.

Categorie

Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by