how to write the nonlinear constraints in fmincon

9 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

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

Weitere Antworten (1)

Stanley Cheng
Stanley Cheng am 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...

Kategorien

Mehr zu Chemistry finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by