Fmincon error not enough input arguments

9 次查看(过去 30 天)
function Variancee = VarObjective(VCVMatx, WStarSave);
Variancee = WStarSave * VCVMatx * WStarSave';
[x, fval] = fmincon('VarObjective', WStarSave', swtOther_A, swtOther_b, AeqMatx, BeqMatx, swtMinWt', swtMaxWt')
%where
WStarSave = 1 X 10 matrix of weights
swtOther_A = [ 0 0 0 0 -1 0 0 -1 0 -1 ; 0 0 0 0 1 0 0 1 0 1];
swtOther_b = [ -0.06 ; +0.40 ];
AeqMatx(1, :) = swtOther_Aeq; where this equals [ 1 1 1 1 1 1 1 1 1 1 ];
AeqMatx(2, :) = returnMatx(1, :);
AeqMatx(3, :) = [1 0 1 0 0 0 1 0 0 0];
BeqMatx(1, :) = swtOther_beq; where this equals [ 1.00 ];
BeqMatx(2, :) = ERGrid(i, 1); where this i will change into the loop
BeqMatx(3, :) = [.22];
THE ERROR WE GET IS THE FOLLOWING:
Not enough input arguments.
Error in VarObjective (line 3)
Variancee = WStarSave * VCVMatx * WStarSave';
Error in fmincon (line 552)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in FEHW7 (line 205)
[x, fval] = fmincon('VarObjective', WStarSave', swtOther_A, swtOther_b, AeqMatx, BeqMatx, swtMinWt', swtMaxWt');%lb -s -inf and ub is +inf
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.

回答(1 个)

Stephan
Stephan 2019-6-4
Your objective function takes 2 input arguments - by default the optimization solvers only use 1 argument, which is the vector of variables to find optimal values for. For passing extra parameters to your óbjective function via the optimization solver have a read here:
for example if your optimization variables are stored in VCVMatx use:
[x, fval] = fmincon(@(VCVMatx)VarObjective(VCVMatx, WStarSave), ...)

类别

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