What is wrong with this vector matrix multiplication?
Show older comments
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
Accepted Answer
More Answers (1)
Walter Roberson
on 7 Mar 2013
1 vote
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 ?
Categories
Find more on App Building 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!