フィルターのクリア

How to use fmincon to optimize two control vectors of a function?

4 ビュー (過去 30 日間)
Jamais avenir
Jamais avenir 2015 年 3 月 31 日
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);

採用された回答

Brendan Hamm
Brendan Hamm 2015 年 3 月 31 日
編集済み: Brendan Hamm 2015 年 3 月 31 日
In the optimization routines in MATLAB the objective function needs to take all of it's design variables as one input. So in your case you would want something like:
function f = myFS(y,sigma)
sv = y(6:7); % sv will be the last 2 elements in the input vector
x = y(1:5); % x is the first 5 elements of the input vector
f = norm(x)^2-sigma*(sv(1)+sv(2)); % Where does sigma come from?
end
I assume sigma is not a design variable so I pass as the next input. This means we need to now define sigma in the workspace and then create a function handle.
sigma = 1;
objective = @(y) myFS(y,sigma);
This will hardcode the value of 1 for sigma into the function 'objective'. Now we can use this with fmincon:
x = fmincon(objective,x0,...)
  1 件のコメント
javiera de la carrera
javiera de la carrera 2017 年 8 月 9 日
Hi Brendan. I have a similar problem, but I have a vector ''q'' that is a design variable that appears in the main function and in the restrictions, and another design variable that appears only in the restriction function. So, I don't know how to put all the design variables in the same vector. Can you help me?
Thanks!

サインインしてコメントする。

その他の回答 (1 件)

Alan Weiss
Alan Weiss 2015 年 3 月 31 日
Perhaps this recent MATLAB Answer will help.
Alan Weiss
MATLAB mathematical toolbox documentation

Community Treasure Hunt

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

Start Hunting!

Translated by