필터 지우기
필터 지우기

What is wrong with this vector matrix multiplication?

조회 수: 3 (최근 30일)
Adam
Adam 2013년 3월 7일
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

채택된 답변

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

추가 답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by