How to use fmincon to optimize two control vectors of a function?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jamais avenir
le 31 Mar 2015
Commenté : javiera de la carrera
le 9 Août 2017
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);
0 commentaires
Réponse acceptée
Brendan Hamm
le 31 Mar 2015
Modifié(e) : Brendan Hamm
le 31 Mar 2015
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 commentaire
javiera de la carrera
le 9 Août 2017
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!
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!