# HG changeset patch # User Rik # Date 1389835313 28800 # Node ID 61dab64aa5a687a995add5e99b2d085747ab84c1 # Parent 906e95708ec1932a5af35837fa2607aa684c8ff4 fminbnd.m: Correctly handle certain functions with odd discontinuities (bug #36923) * fminbnd.m: Correctly get a minimum result even for functions with specifically placed discontinuities which were defeating the Golden Section search. Add a %!test which verifies the behavior. diff --git a/scripts/optimization/fminbnd.m b/scripts/optimization/fminbnd.m --- a/scripts/optimization/fminbnd.m +++ b/scripts/optimization/fminbnd.m @@ -170,7 +170,7 @@ ## update a, b, v, w, and x - if (fu <= fval) + if (fu < fval) if (u < x) b = x; else @@ -283,4 +283,5 @@ %!assert (fminbnd (@(x) (x - 1e-3)^4, -1, 1, opt0), 1e-3, 10e-3*sqrt (eps)) %!assert (fminbnd (@(x) abs (x-1e7), 0, 1e10, opt0), 1e7, 10e7*sqrt (eps)) %!assert (fminbnd (@(x) x^2 + sin (2*pi*x), 0.4, 1, opt0), fzero (@(x) 2*x + 2*pi*cos (2*pi*x), [0.4, 1], opt0), sqrt (eps)) +%!assert (fminbnd (@(x) x > 0.3, 0, 1) < 0.3)