diff -r 97b4bd6f0925 scripts/optimization/fzero.m --- a/scripts/optimization/fzero.m Sat Feb 13 08:17:21 2010 +0100 +++ b/scripts/optimization/fzero.m Mon Feb 15 10:24:07 2010 -0800 @@ -36,10 +36,12 @@ ## The algorithm converged to a solution. ## @item 0 ## Maximum number of iterations or function evaluations has been exhausted. ## @item -1 ## The algorithm has been terminated from user output function. +## @item -2 +## The algorithm may have converged to a singular point. ## @end itemize ## @seealso{optimset, fsolve} ## @end deftypefn ## This is essentially the ACM algorithm 748: Enclosing Zeros of @@ -279,10 +281,17 @@ if (itype == 2) mba = mu * (b - a); endif endwhile + ## Check solution for a singularity by examining slope + if (info == 1) + if ((b - a) != 0 && abs ((fb - fa)/(b - a)) > max (1e6, 0.5/tolx) ) + info = -2; + endif + endif + output.iterations = niter; output.funcCount = nfev; output.bracket = [a, b]; output.bracketf = [fa, fb];