MATLAB Answers

What is wrong with this vector matrix multiplication?

11 views (last 30 days)
Adam
Adam on 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

  0 Comments

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 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

  0 Comments

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 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 ?

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by