how to write the nonlinear constraints in fmincon
2 views (last 30 days)
Show older comments
Stanley Cheng
on 9 Jul 2014
Answered: Stanley Cheng
on 9 Jul 2014
Hi everyone,
I am using the fmincon in matlab to minimize the objective value as
F=-(x(1)^2+x(2)^2+x(3)^2) .
So the objective function I write is
function Fexternal=myfun(x)
x1=x(1);
x2=x(2);
x3=x(3);
Fexternal=-(x1^2+x2^2+x3^2).
x is the 3*1 vector design variable in this problem.
However, there are also some other nonlinear constraints for this problem, i.e.
F1<=120;
F2<=100;
F3<=130;
F4<=140;
F5<=150;
F6<=20.
and F1~F6 are all the functions of the three variables x1~x3,i.e.
F1= F1(x(1),x(2),x(3));
F2= F2(x(1),x(2),x(3));
F3= F3(x(1),x(2),x(3));
F4= F4(x(1),x(2),x(3));
F5= F5(x(1),x(2),x(3));
F6= F6(x(1),x(2),x(3));
They are all long expressions and not simple to write all them explicitly.
How can the nonlinear constraint functions to be written as a .m file?
THX very much for your help!
0 Comments
Accepted Answer
George Papazafeiropoulos
on 9 Jul 2014
Define the constraint function as follows:
function [C,Ceq]=confun(x)
F1=...
F2=...
F3=...
F4=...
F5=...
F6=...
C=[F1-120;F2-100;F3-130;F4-140;F5-150;F6-20];
Ceq=[];
and use the command:
X = fmincon('Fexternal',x0,[],[],[],[],[],[],'confun')
0 Comments
More Answers (1)
See Also
Categories
Find more on Nonlinear Optimization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!