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
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)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 1×3
0.1599 0.2165 0.2236
c1 = 16000*x(1)^2 - 1000
c1 = -590.9768
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
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)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 1×3
0.1599 0.2165 0.2236

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by