I am trying to use the function fmincon for multiple nonlinear inequality constraints, and the output given does not satisfy all the inequality constraint
5 次查看(过去 30 天)
显示 更早的评论
objective = @(x) - 16000*x(1)^2 - 32000*x(2)^2 - 40000*x(3)^2;
x0 = [0.05, 0.05, 0.07];
A = [];
b = [];
aeq = [1,1,1];
beq =0.6;
lb = [0.05, 0.05, 0.07];
ub = [];
nonlincon = @nlcon;
fmincon(objective, x0, A,b,aeq,beq,lb,ub,nonlincon,options)
output: 0.2833 0.0500 0.2667
c(1) = 16000*x(1)^2 - 1000 = 284.44444 %(which is not less than 0)
function [c,ceq] = nlcon(x)
c(1)= 16000*x(1)^2 - 1000;
c(2)= 32000*x(2)^2 - 1500;
c(3)= 40000*x(3)^2 - 2000;
end
2 个评论
Matt J
2022-5-16
Works fine for me:
objective = @(x) - 16000*x(1)^2 - 32000*x(2)^2 - 40000*x(3)^2;
x0 = [0.05, 0.05, 0.07];
A = [];
b = [];
aeq = [1,1,1];
beq =0.6;
lb = [0.05, 0.05, 0.07];
ub = [];
nonlincon = @nlcon;
x=fmincon(objective, x0, A,b,aeq,beq,lb,ub,nonlincon)
c1 = 16000*x(1)^2 - 1000
function [c,ceq] = nlcon(x)
c(1)= 16000*x(1)^2 - 1000;
c(2)= 32000*x(2)^2 - 1500;
c(3)= 40000*x(3)^2 - 2000;
ceq=[];
end
回答(1 个)
Matt J
2022-5-16
编辑:Matt J
2022-5-16
As a general rule, you should avoid nonlinear constraints when they have a linear equivalent. In your case, the nonlinear constraints can be re-expressed as simple bounds:
objective = @(x) - 16000*x(1)^2 - 32000*x(2)^2 - 40000*x(3)^2;
x0 = [0.05, 0.05, 0.07];
A = [];
b = [];
aeq = [1,1,1];
beq =0.6;
lb = [0.05, 0.05, 0.07];
ub = sqrt( [1000, 1500, 2000]./[16000,32000,40000] );
x=fmincon(objective, x0, A,b,aeq,beq,lb,ub)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!