Reputation: 345
I have a function of 2 different vector. These are the control vector (decision variables) of the function. I want to use fmincon
to optimize this function and also get the both control vector results separately.
I have tried to use handle ,@, but I got an error.
The function is:
function f = myFS(x,sv) % x is a vector (5,1)
f = norm(x)^2-sigma*(sv(1)+sv(2));
end
%% I tried to write fmincone
to consider both control vectors (x and sv)
[Xtemp(:,h2),Fval, fiasco] = fmincon(@(x,sv)myFS(x,sv)...
,xstart,[],[],[],[],VLB,VUB,@(x,sv)myCon(sv),options);
Here is the error I get:
Error using myFS (line 12) Not enough input arguments.
Error in fmincon (line 564) initVals.f = feval(funfcn{3},X,varargin{:});
Error in main_Econstraint (line 58) [Xtemp(:,h2),Fval, fiasco] = fmincon('myFS',xstart,[],[],[],[],VLB,VUB,@(x,sv)myCon(sv),options);
Thanks
Upvotes: 1
Views: 1132
Reputation: 582
fmincon expects your function to be of a single variable, there is no getting around that, but see:
http://se.mathworks.com/help/optim/ug/passing-extra-parameters.html
for example, if both x, cv are variables of the optimization you can combine them and then split them in the actual objective
for example
x_cv = vertcat(x, cv)
and then x = x_cv(1:5); cv = x_cv(6:end)
'
if cv is not a variable of the optimization, then 'freeze it' as the link above suggests
Upvotes: 2