Inverse of a function gives different results than the negative function with fmincon
Mostra commenti meno recenti
Hello,
I have a function f(x) which I am trying to maximize. Following the suggestions on: Maximizing an Objective - MATLAB & Simulink (mathworks.com), 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?
Thanks.
2 Commenti
Mario Malic
il 21 Dic 2020
If you want to minimise, then it's f(x), if you want to maximise then it's -f(x).
Alessandro Maria Laspina
il 22 Dic 2020
Risposta accettata
Più risposte (2)
Bruno Luong
il 22 Dic 2020
0 voti
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.
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.
Categorie
Scopri di più su Nonlinear Optimization in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!