I would expect that at the very least, fmincon should remember seeing a better value earlier and return that one, but it also seems odd to spend so many iterations moving away from the starting point.
options = optimset('fmincon');
options = optimset(options, 'AlwaysHonorConstraints', 'none');
options = optimset(options, 'Algorithm', 'interior-point');
options = optimset(options, 'TolX', 1e-15);
options = optimset(options, 'GradObj', 'on');
options = optimset(options, 'TolCon', 1e-5);
options = optimset(options, 'TolFun', 1e-11);
Iter F-count f(x) Feasibility First-order optimality Norm of step
0 1 -5.072909e-001 0.000e+000 2.958e-002
1 2 -5.058305e-001 3.331e-016 1.133e-001 3.056e-001
2 3 -5.029251e-001 2.220e-016 8.092e-002 6.062e-001
3 5 -5.027718e-001 0.000e+000 6.662e-002 3.561e-002
4 6 -5.028418e-001 0.000e+000 6.660e-002 1.829e-002
5 8 -5.028396e-001 0.000e+000 6.242e-002 1.849e-003
...
49 186 -5.045984e-001 1.110e-016 6.030e-002 2.359e-003
50 187 -5.045930e-001 2.220e-016 2.312e-002 1.404e-003
51 188 -5.045852e-001 2.220e-016 2.300e-002 2.357e-003
52 204 -5.045852e-001 0.000e+000 3.191e-002 4.363e-006
fval =
-0.504585222146531
You might do better with the sqp algorithm or the active-set algorithm.
The way the interior-point algorithm works is to use a slightly
different objective function, one that penalizes being close to the
boundary, and it reduces the penalty as it iterates. The active-set and
sqp algorithms don't mind being right up against a bound. I suggest you
try the sqp algorithm first, it is more robust than active-set.
Alan Weiss
MATLAB mathematical toolbox documentation