changeset 25746:e1b69ea2d39a

maint: merge stable to default.
author Rik <rik@octave.org>
date Sun, 05 Aug 2018 21:24:00 -0700
parents 3ddd74bd7b11 (current diff) 092bb49b6962 (diff)
children 3c45cfac7692
files
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/optimization/fzero.m	Sun Jul 01 20:11:19 2018 -0400
+++ b/scripts/optimization/fzero.m	Sun Aug 05 21:24:00 2018 -0700
@@ -152,7 +152,11 @@
     ## Try to find a value for b which brackets a zero-crossing
 
     ## For very small values, switch to absolute rather than relative search
-    ifelse (abs (a) < .001, aa = sign (a) * 0.1, aa = a);
+    if (abs (a) < .001)
+      aa = ifelse (a == 0, 0.1, sign (a) * 0.1);
+    else
+      aa = a;
+    endif
     ## Search in an ever-widening range around the initial point.
     for srch = [-.01 +.025 -.05 +.10 -.25 +.50 -1 +2.5 -5 +10 -50 +100 -500 +1000]
       b = aa + aa*srch;
@@ -373,3 +377,5 @@
 %! opt0 = optimset ("tolx", 0);
 %!assert (fzero (@cos, [0, 3], opt0), pi/2, 10*eps)
 %!assert (fzero (@(x) x^(1/3) - 1e-8, [0,1], opt0), 1e-24, 1e-22*eps)
+%!assert <*54445> (fzero (@ (x) x, 0), 0)
+%!assert <*54445> (fzero (@ (x) x + 1, 0), -1)