# HG changeset patch # User Massimiliano Fasi # Date 1411143845 -7200 # Node ID 0f79fa9b3a8cd1dadc24e30bc84477a7f43accf2 # Parent 8ee14c64ab5fca22acf99890aafb9c2873c46d11 fmindbnd.m: Check input range is low to high (bug #43219). * fminbnd.m: Validate that lower bound of input range is smaller than upper bound. Add BIST tests for new input validation. diff -r 8ee14c64ab5f -r 0f79fa9b3a8c scripts/optimization/fminbnd.m --- a/scripts/optimization/fminbnd.m Tue Dec 30 08:31:51 2014 -0800 +++ b/scripts/optimization/fminbnd.m Fri Sep 19 18:24:05 2014 +0200 @@ -70,6 +70,11 @@ if (nargin < 2 || nargin > 4) print_usage (); endif + + if (xmin > xmax) + error ("Octave:invalid-input-arg", + "fminbnd: the lower bound cannot be greater than the upper one"); + endif if (ischar (fun)) fun = str2func (fun, "global"); @@ -284,4 +289,7 @@ %!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) +%!assert (fminbnd (@(x) sin (x), 0, 0), 0, eps) +%!error fminbnd (@(x) sin (x), 0, -pi) +