필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
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