changeset 10337:7c97da90fc8f

check for discontinuities in fzero
author Rik <rdrider0-list@yahoo.com>
date Fri, 19 Feb 2010 07:06:36 +0100
parents 1603dfe72933
children 21dd58bd683c
files scripts/ChangeLog scripts/optimization/fzero.m
diffstat 2 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Feb 19 06:58:13 2010 +0100
+++ b/scripts/ChangeLog	Fri Feb 19 07:06:36 2010 +0100
@@ -1,3 +1,7 @@
+2010-02-19  Rik <octave@nomad.inbox5.com>
+
+	* optimization/fzero.m: Add test for discontinuity at the end.
+
 2010-02-18  John W. Eaton  <jwe@octave.org>
 
 	* image/imfinfo.m: Don't handle file time stamp here.
--- a/scripts/optimization/fzero.m	Fri Feb 19 06:58:13 2010 +0100
+++ b/scripts/optimization/fzero.m	Fri Feb 19 07:06:36 2010 +0100
@@ -38,6 +38,8 @@
 ## Maximum number of iterations or function evaluations has been exhausted.
 ## @item -1
 ## The algorithm has been terminated from user output function.
+## @item -5
+## The algorithm may have converged to a singular point.
 ## @end itemize
 ## @seealso{optimset, fsolve} 
 ## @end deftypefn
@@ -133,6 +135,8 @@
     error ("fzero:bracket", "fzero: not a valid initial bracketing");
   endif
 
+  slope0 = (fb - fa) / (b - a);
+
   itype = 1;
 
   if (abs (fa) < abs (fb))
@@ -281,6 +285,13 @@
     endif
   endwhile
 
+  ## Check solution for a singularity by examining slope
+  if (info == 1)
+    if ((b - a) != 0 && abs ((fb - fa)/(b - a) / slope0) > max (1e6, 0.5/tolx))
+      info = -5;
+    endif
+  endif
+
   output.iterations = niter;
   output.funcCount = nfev;
   output.bracket = [a, b];