MATLAB Answers

0

Fmincon error not enough input arguments

Asked by Emil Georgiev on 4 Jun 2019
Latest activity Answered by Stephan
on 4 Jun 2019
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.

  0 Comments

Sign in to comment.

1 Answer

Answer by Stephan
on 4 Jun 2019

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), ...)

  0 Comments

Sign in to comment.