필터 지우기
필터 지우기

inner matrix dimensions must agree error in the function?

조회 수: 1 (최근 30일)
Sameer
Sameer 2014년 5월 29일
편집: Image Analyst 2014년 5월 30일
function [f] = objfun(W,VCVMatx)
%function for varience of the portfolio with swtN stocks
f =W*VCVMatx*W';
this is my function I am trying to run in the main program. However, when run in the main program, it keeps giving me :
Error using * Inner matrix dimensions must agree.
W is a 10(N)X1 vector, while VCVMatx is an NXN vector?
Does anyone see anything wrong, considering I multiplied it by a transposed W'
I tried running fmincon, but in the main program it says the function matrix dimensions do not agree.
f = (W'*VCVMatx)*W;
i=1;
while i<=rows(ERGrid);
ExpectedReturn = ERInc(i);
[W] = fmincon('objfun',x0,swtOther_A,swtOther_b,swtOther_Aeq,swtOther_beq,swtMinWt1,swtMaxWt1,[],options);
ERGrid(2:swtN+1,i) = W;
i=i+1;
end;
W' is a 1X10 vector while VCVMatx is a 10X10 matrix and W is 10X1 vector
fmincon cannot run as a result.

답변 (1개)

Geoff Hayes
Geoff Hayes 2014년 5월 30일
The first matrix product (in the equation) is the problem. Since W is Nx1 and VCVMatx is NxN, then W*VCVMtx will fail due to the incompatible dimensions of the two matrices. If you are just expecting a single value, then the equation should be re-written as
f = W'*VCVMtx*W;
  댓글 수: 29
Sameer
Sameer 2014년 5월 30일
would you happen to know how to place two linear equality constraints in one fmincon function? thanks.
Geoff Hayes
Geoff Hayes 2014년 5월 30일
No, unfortunately I have never used that function (nor have the toolbox for it).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by