MATLAB: The solution provided by fmincon does not satisfy the constraints

fminconoptimization

Hi! I'm trying to optimize a function subcject to both inequality and inequality constraints, but the solution provided by fmincon does not satisfy all of the constraints? How can this be? I'm new to optimization and quite confused by this. I'm grateful for any input to my problem! My setup looks like this:
LB = [-10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -10000 -10000 -10000 -10000 0 0 0 0 0 0 0 0 0 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ]; % Lower bound
UB = [10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 1 1 1 1 1 1 1 1 10000 ]; % Upper bound
ConstraintFunction = @simple_constraints;
x0=[-241.1;-257.99;-245.53;-262.92;-256.37;-274.60;-265.20;-285.26;0.42708;0.38135;0.56409;0.54010;0.11665;0.097351;0.701129;0.659724;0.15588;0.16664;0.064814;0.069286;0.078117;0.10459;1.1844;0.97493;1.0487;0.85453;24.28;19.96;27.42;22.77;0.0649;0.39068;0.31430;0.021430;0.02568;0.071780;0.082909;0.564;0.601;0.206;0.202;0.024;0.021;0.059;0.59;2;0.1;0.1;0.1;0.1;0.1;0.1;0.1];
optcon = optimoptions('fmincon','display','iter');
[x,fval] = fmincon(@(x) simple_fitness(x),x0,[],[],[],[],LB,UB, ...
@(x) simple_constraints(x)),optcon;

Best Answer

We need to see the rest of output.message,
message: 'Solver stopped premature...'
but it is clearly telling you that fmincon did not finish. The exitflag tells you this, too.
It reached either the maximum number of iterations or the maximum number of function evaluations.
This at least answers the question as to why your constraints are not satisfied.
You probably want to try increasing MaxFunEvals. Because you are using the default finite difference calculations of the derivatives, fmincon needs to do at least N+1=56 function evaluations per iteration, where N is the number of unknowns that you have. It is strange to me that fmincon doesn't set the default MaxFunEvals adaptively based on MaxIter and the number of unknowns, but apparently, it doesn't...
When you do this, if you find that fmincon is taking a painfully large number of iterations to converge, then there is likely something mathematically dysfunctional about your objective function or constraints.