Can Fmincon recover from an error in evaluating the cost function?
3 views (last 30 days)
Show older comments
Amir Patel
on 4 Jun 2013
Commented: Farshid R
on 26 Sep 2022
Hi
I'm using fmincon to determine the optimal torque trajectory for a mutlibody simulation. I've approximated the input torque as piece-wise linear function.
I'm using fmincon as I would like to minimize the time it takes to bring the system to rest - this is my "cost function". This is determined by simulation of my model and then determining the cost. A similar approach is done to evaluate my nonlinear constraints.
Unfortunately, sometimes if the torque trajectory attempted by fmincon is too great, the simulation crashes with the message "Derivative input 1 of 'optimModel/Integrator1' at time 0.359 is Inf or NaN" and then the function stops. This is understandable as the body system spins around violently.
Is there a way for fmincon to recover from this? ie. to assign a cost to this value and move to the next attempt?
Or alternatively, does Global Optimization toolbox have functions with provision to do this? I realize that my cost function must obviously be non-smooth and some solutions cause instability in my simulation.
Any suggestions would be much appreciated.
Kind Regards
Amir
0 Comments
Accepted Answer
Shashank Prasanna
on 4 Jun 2013
Alan will correct me if I am wrong, but fmincon is derivative based and not particularly good friends with non-smooth problems, You can try a different solver based on this information for the nature of your cost function:
I would ask you to try fminsearch first to see if you get somewhere, but you seem to have bound constraints. fminbnd can do bounds but for single variable cost functions.
Alternatively you can gravitate towards Global Optim solutions based on this decision table:
3 Comments
Shashank Prasanna
on 4 Jun 2013
Yes patternsearch will be able to handle this type of problem, but would be slower. If you are not doing the optimization online or during simulation then this is a good place to start. You could also try multistart and globalsearch which run a chosen solver with different starting points. Secondly if you don't mind changing your cost function, then you could try Matt J suggestion on fitting a spline which would be differentiable.
This link may be of help on what to do when a solver fails:
More Answers (2)
Alan Weiss
on 4 Jun 2013
The sqp and interior-point algorithms are robust to evaluation failures, as long as the initial point x0 has a well-defined objective there. See the release notes for R2011a.
Alan Weiss
MATLAB mathematical toolbox documentation
9 Comments
Farshid R
on 26 Sep 2022
Thank you. Sorry, I replied late. The link to my question is:
https://www.mathworks.com/matlabcentral/answers/1812615-optimization-with-fmincon-command-in-simulink
Farshid R
on 26 Sep 2022
https://www.mathworks.com/matlabcentral/answers/1812615-optimization-with-fmincon-command-in-simulink
Matt J
on 4 Jun 2013
Edited: Matt J
on 4 Jun 2013
I've approximated the input torque as piece-wise linear function.
A piece-wise linear input will obviously not have bounded derivatives. To achieve bounded derivatives in FMINCON, you could and probably should approximate the torque using a 2nd order smooth function instead, e.g. using the SPLINE command or with the 'cubic' option of any of MATLAB's interpolation commands.
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!