What is wrong with this vector matrix multiplication?

16 vues (au cours des 30 derniers jours)
Adam
Adam le 7 Mar 2013
Hi
I have a formular saying that: P_loss = P(transposed)*B*P + B0*P + B00
P = [P1 P2 P3] 1x3 vector, B is a 3x3 matrix, B0 = [-0.08 0 0.02]is a 1x3 vector, and B00 = 0.004is a constant.
How can i calculate this in matlab?
my code is:
P = [100 300 200]
%B-matrices
B = [0.0003 0 0; 0 0.0002 0; 0 0 0.0005]
B_0 = [-0.08 0 0.02]
B_00 = 0.04;
P_loss = P'*B*P+B0*P+B00
And i get this error:
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> test at 10
P_loss = P'*B*P+B0*P+B0

Réponse acceptée

James Tursa
James Tursa le 7 Mar 2013
P'*B*P+B0*P+B0
(3 x 1) * (3 x 3) * (1 x 3) + (1 x 3) * (1 x 3) + (1 x 1)
So none of the inner dimensions match above.
Maybe you want this instead:
P*B*P'+B0*P'+B0

Plus de réponses (1)

Walter Roberson
Walter Roberson le 7 Mar 2013
The expression includes B0*P . B0 is 1 x 3, and P is 1 x 3, so you are trying to matrix multiply with (1, 3) (1, 3) which cannot work as the "3" does not match the "1".
Notice that in the subexpression you have, B*P, your B is 3 x 3, so you are doing (3,3) (1, 3), and that cannot work either.
Perhaps your P should be 3 x 1 instead of 1 x 3 ?

Catégories

En savoir plus sur App Building dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by