What is wrong with this vector matrix multiplication?
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
James Tursa
2013 年 3 月 7 日
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 件のコメント
その他の回答 (1 件)
Walter Roberson
2013 年 3 月 7 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!