Asking for help with syntax for fmincon
Afficher commentaires plus anciens
Hi all,
I am trying out the standard given examples in MATLAB for fmincon usage. I am referring to this particular example:
openExample('optim/NonlinearConstraintsExample')
fun = @(x) 100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
lb = [0,0.2];
ub = [0.5,0.8];
function [c,ceq] = circlecon(x)
c = (x(1)-1/3)^2 + (x(2)-1/3)^2 - (1/3)^2;
ceq = [];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [1/4,1/4];
nonlcon = @circlecon;
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
I want to modify it to have multiple variables separately in separate vectors but still be able to solve the final problem. For example I make the following modification:
fun = @(x,y) 100*(x(2)-x(1)^2)^2 + (1-x(1))^2 + 100*(y(2)-y(1)^2)^2 + (1-y(1))^2;
lb = [0,0.2,0,0.2];
ub = [0.5,0.8,0.5,0.8];
function [c,ceq] = circlecon(x,y)
c = (x(1)-1/3)^2 + (x(2)-1/3)^2 - (1/3)^2 + (y(1)-1/3)^2 + (y(2)-1/3)^2 - (1/3)^2;
ceq = [];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [1/4,1/4];
y0 = [1/4,1/4];
nonlcon = @circlecon;
Notice that I have introduced a new 'y' variable. I can't figure out how to correctly call the fmincon function to solve the problem.
Kindly advise please.
Regards
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!