fmincon with nonlcon does not converge to optimum value

function [c ceq] = test_simple(x)
c=[];
ceq=x(1)*x(2);
end
clear;
clc;
fun = @(x) -x(1)^2-x(2)^2
lb = [0;0.2;];
ub = [0.5;0.8];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [0;0.1];
nonlcon=@test_simple;
options = optimset('MaxFunEvals',Inf,'MaxIter',5000,...
'Algorithm','interior-point','Display','iter');
[x1, fval1] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,optimset)
optimum value is 0 0.8 but, matlab execution value is
x1 =
0.0000
0.7153
how do i fix it?

1 Comment

You don't have to pass "optimset" to "fmincon", but "options":
[x1, fval1] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
Best wishes
Torsten.

Sign in to comment.

 Accepted Answer

The 'interior-point' algorithm cannot allow for points that are right on a boundary, yet your nonlinear constraint attempts to force the points to the boundary. I suggest that you do one of the following:
  • Change the lower bound on x(1) to a negative number such as lb = [-0.1;0.2]
  • Use the 'sqp' algorithm
  • In any case, use a feasible initial point, such as [1e-8;0.3]
Also, after fmincon finishes, try running it again from the final point if the answer isn't reliable (exit flag not equal to 1).
Alan Weiss
MATLAB mathematical toolbox documentation

More Answers (1)

fmincon is not a global optimizer. You need one of the tools from the Global Optimization Toolbox, such as ga or particleswarm or bounded simulated annealing or patternsearch. (Note: none of those can promise to find the global minima either -- but fmincon doesn't even try.)

Community Treasure Hunt

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

Start Hunting!