MATLAB: Fminbnd warning message: Exiting: Maximum number of iterations has been exceeded – increase MaxIter option.

fminbndMATLABnumber of iterations

I use fminbnd to find the minimum of a function (myfunc), and wish to limit the number of iterations to 8. I know by experiment that this gives a sufficiently accurate result. So I call it as follows:-
[x,fval,exitflag]= fminbnd(@myfunc,0,10,optimset('MaxIter',8));
Under some circumstances it generates the following error message:-
Exiting: Maximum number of iterations has been exceeded
- increase MaxIter option.
Current function value: 0.381169
How do I stop this being printed out? warning('OFF') has no effect.
As a specific example of myfunc, this produces the above error message:-
function result = myfunc( alpha)
factor=sqrt(10*(1+alpha^2));
result=1/4*( erfc(sqrt(2)/factor)+ erfc(alpha*0.1*sqrt(2)/factor));
end

Best Answer

To avoid exit messages and this warning, set the Display option to 'off':
opts = optimset('MaxIter',8,'Display','off');
[x,fval,exitflag]= fminbnd(@myfunc,0,10,opts);
Alan Weiss
MATLAB mathematical toolbox documentation