stop fmincon if encounter warning about rank
Show older comments
Hi,
I'm running fmincon using the sqp algorithm to run a montecarlo.
Sometimes (a couple out of a hundred) it encounters a matrix close to singluar and gets caught.
Is there a way to stop the optimizer and move on to the next with an exitflag that will let me know it did so?
I tried interior point, but after 10000 maxiter it didn't get close to the minimum that sqp was finding, so seems like sqp is better for this problem if I can find a way to cancel the optimization and move on if it encounters the warning.
Thanks for any tips.
Answers (1)
You can define your own stopping conditions using the OutputFcn option, see here
I don't think it offers a way to control the native exitflag output argument, but you can send the flag to a global variable, or use nested functions that share variables.
9 Comments
JD
on 7 Feb 2014
Matt J
on 7 Feb 2014
You can also use LASTWARN to get info about whether an RCOND-->0 condition has occurred.
JD
on 7 Feb 2014
I assume the warning you're getting is the following?
>> A=[1e28 0; 0 1]; b=[2;2]; A\b;
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.000000e-28.
If so, you can use laswarn to obtain it. I'm not sure the MSGIDs are independent of MATLAB version, however. In my version, it is
>> [~,msgid]=lastwarn
msgid =
MATLAB:nearlySingularMatrix
Matt J
on 7 Feb 2014
As far as I can tell tstart is not a persistent variable, so its value will be forgotten on subsequent calls to the OutputFcn.
As for msgchk, I don't understand why you wouldn't just do
if strcmp(msgid,'MATLAB:nearlySingularMatrix')
stop = true;
end
Finally, you should issue your own warning when stopping prematurely, so that lastwarn will be reset.
JD
on 8 Feb 2014
Matt J
on 8 Feb 2014
Like I said, the way you are doing it now seems fine, except that tstart would have to be made persistent, and reset to 0 at an appropriate point.
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!