how to write the nonlinear constraints in fmincon

3 views (last 30 days)
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!

Accepted Answer

George Papazafeiropoulos
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')

More Answers (1)

Stanley Cheng
Stanley Cheng on 9 Jul 2014
Hi George,
First thx very much for your input!
However, in the functions of F1~F6, there are other variables g, which are also used in the main m.file.
Besides, the x1~x3 are not explicitly expressed in F1~F6:
f1=f1(x1~x3,g);
f2=f2(x1~x3,g);
f3=f3(x1~x3,g);
and
F1=F1(f1,f2,f3);
F2=F2(f1,f2,f3);
F3=F3(f1,f2,f3);
F4=F4(f1,f2,f3);
F5=F5(f1,f2,f3);
F6=F6(f1,f2,f3);
These are the hard points...

Products

Community Treasure Hunt

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

Start Hunting!