MATLAB Answers

Inverse of a function gives different results than the negative function with fmincon

1 view (last 30 days)
I have a function f(x) which I am trying to maximize. Following the suggestions on: Maximizing an Objective - MATLAB & Simulink (, I can define the function to minimize on fmincon as -f(x). This works as well since my boundaries indicate that x needs to be in the positive regime, and my function is actually one of the two variables x itself, specfically f(x)=-x(1).
However, I previously used to define my variable as the inverse of itself in case I wanted to maximize it, so f(x)=1/(x(1)). Now oddly enough, fmincon gives me different results if I define my function this way... I would love to share my files but I cannot for confidentiality. Assuming that the boundaries are not the problem, is this expected behavior with the fmincon solver? Or am I making a mistake somewhere else?
Alessandro Maria Laspina
Alessandro Maria Laspina on 22 Dec 2020
Why not 1/f(x)? If the bounds are positive, and the objective function is the optimization variable itself, this should also minimize the function when f(x) gets larger.

Sign in to comment.

Accepted Answer

Alan Weiss
Alan Weiss on 22 Dec 2020
The problem could be related to a few things, such as numerical stability and the presence of multiple local minima.
For numerical stability, you didn't tell us the typical ranges of your variables. But for very large or small values, 1/x and -x behave very differently. I expect that your solution might be a large or small number.
For multiple local minima, the fmincon algorithm can take different paths dependinig on many problem inputs, and both results can be true local minima and yet differ.
Without more information, these general optimization characteristics are the best I can offer.
Alan Weiss
MATLAB mathematical toolbox documentation

More Answers (2)

Bruno Luong
Bruno Luong on 22 Dec 2020
If you apply a non-llinear transformation of your decision variables, I would expect the solver behave differently.
The solver is not a miracle blackbox that you can twist in any direction and expect it to be robust.
I relies on the fact that the minimum is on the attraction basin, that the Hessian is more or less change not so quickly, etc....
Transform x -> 1/x will be a major change.

Matt J
Matt J on 22 Dec 2020
Edited: Matt J on 22 Dec 2020
With f(x)=-x1, the norm of the gradient of f is always 1. However, with f(x)=1/x1, the norm of the gradient will fall off quadratically as x1 gets larger. It therefore becomes possible that the OptimalityTolerance threshold and/or the FunctionTolerance threshold will be reached sooner than it otherwise would and cause the iterations to stop prematurely. You can try reducing these thresholds to see if there is a helpful effect. However, f(x)=-x1 is probably ythe better way to go, for reasons that others have already mentioned.

Community Treasure Hunt

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

Start Hunting!