how to write the nonlinear constraints in fmincon
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
George Papazafeiropoulos
2014-7-9
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 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Nonlinear Optimization 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!