Mercurial > jwe > octave
changeset 24066:d9b0d8ae734f
Update tolerances in BIST tests for quad functions.
* quadgk.m: Use 1e-10 for absolute tolerances or -1e-6 for relative tolerances
in assert statements.
* quadl.m: Print a warning when Octave overrides users specified tolerance with
eps. Use 1e-6 for absolute tolerances. Add new BIST test.
* quadv.m: Set default value of "trace" input to false in function prototype.
Ues 1e-6 for absolute tolerances. Add new BIST test.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 20 Sep 2017 17:23:50 -0700 |
parents | 34506e4e3b04 |
children | 5b88383b9a69 |
files | scripts/general/quadgk.m scripts/general/quadl.m scripts/general/quadv.m |
diffstat | 3 files changed, 30 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/quadgk.m Wed Sep 20 14:45:19 2017 -0700 +++ b/scripts/general/quadgk.m Wed Sep 20 17:23:50 2017 -0700 @@ -459,24 +459,26 @@ endfunction -%!assert (quadgk (@sin,-pi,pi), 0, 1e-6) -%!assert (quadgk (inline ("sin"),-pi,pi), 0, 1e-6) -%!assert (quadgk ("sin",-pi,pi), 0, 1e-6) -%!assert (quadgk (@sin,-pi,pi, "waypoints", 0, "MaxIntervalCount", 100, "reltol", 1e-3, "abstol", 1e-6, "trace", false), 0, 1e-6) -%!assert (quadgk (@sin,-pi,pi, 1e-6,false), 0, 1e-6) +%!assert (quadgk (@sin,-pi,pi), 0, 1e-10) +%!assert (quadgk (inline ("sin"),-pi,pi), 0, 1e-10) +%!assert (quadgk ("sin",-pi,pi), 0, 1e-10) +%!assert (quadgk (@sin,-pi,pi, "WayPoints", 0, "MaxIntervalCount", 100, +%! "RelTol", 1e-3, "AbsTol", 1e-6, "trace", false), 0, 1e-6) +%!assert (quadgk (@sin,-pi,pi, 1e-6, false), 0, 1e-6) %!assert <51867> (quadgk (@(x) x, 0, 0), 0, 0) -%!assert (quadgk (@sin,-pi,0), -2, 1e-6) -%!assert (quadgk (@sin,0,pi), 2, 1e-6) -%!assert (quadgk (@(x) 1./sqrt (x),0,1), 2, 1e-6) -%!assert (quadgk (@(x) abs (1 - x.^2),0,2, "Waypoints", 1), 2, 1e-6) -%!assert (quadgk (@(x) 1./(sqrt (x) .* (x+1)),0,Inf), pi, 1e-6) -%!assert (quadgk (@(z) log (z),1+1i,1+1i, "WayPoints", [1-1i, -1,-1i, -1+1i]), -pi * 1i, 1e-6) -%!assert (quadgk (@(x) exp (-x .^ 2),-Inf,Inf), sqrt (pi), 1e-6) -%!assert (quadgk (@(x) exp (-x .^ 2),-Inf,0), sqrt (pi)/2, 1e-6) +%!assert (quadgk (@sin,-pi,0), -2, 1e-10) +%!assert (quadgk (@sin,0,pi), 2, 1e-10) +%!assert (quadgk (@(x) 1./sqrt (x),0,1), 2, 1e-10) +%!assert (quadgk (@(x) abs (1 - x.^2),0,2, "Waypoints", 1), 2, 1e-10) +%!assert (quadgk (@(x) 1./(sqrt (x) .* (x+1)),0,Inf), pi, 1e-10) +%!assert (quadgk (@(z) log (z),1+1i,1+1i, "WayPoints", [1-1i, -1,-1i, -1+1i]), +%! -pi * 1i, 1e-10) +%!assert (quadgk (@(x) exp (-x .^ 2),-Inf,Inf), sqrt (pi), -1e-6) +%!assert (quadgk (@(x) exp (-x .^ 2),-Inf,0), sqrt (pi)/2, -1e-6) %!test %! f = @(x) x .^ 5 .* exp (-x) .* sin (x); -%! assert (quadgk (f, 0, inf, "RelTol", 1e-8, "AbsTol", 1e-12), -15, 2e-12); +%! assert (quadgk (f, 0, inf, "RelTol", 1e-8, "AbsTol", 1e-12), -15, -1e-8); ## Test input validation %!error quadgk (@sin)
--- a/scripts/general/quadl.m Wed Sep 20 14:45:19 2017 -0700 +++ b/scripts/general/quadl.m Wed Sep 20 17:23:50 2017 -0700 @@ -80,6 +80,8 @@ elseif (! isscalar (tol) || tol < 0) error ("quadl: TOL must be a scalar >=0"); elseif (tol < eps) + warning ("quadl: TOL specified is smaller than machine precision, using %g", + tol); tol = eps; endif if (isempty (trace)) @@ -166,7 +168,7 @@ ## basic functionality -%!assert (quadl (@(x) sin (x), 0, pi), 2, 5e-15) +%!assert (quadl (@(x) sin (x), 0, pi), 2, 1e-6) ## the values here are very high so it may be unavoidable that this fails %!assert (quadl (@(x) sin (3*x).*cosh (x).*sinh (x),10,15, 1e-3), @@ -174,7 +176,7 @@ ## extra parameters %!assert (quadl (@(x,a,b) sin (a + b*x), 0, 1, [], [], 2, 3), -%! cos(2)/3 - cos(5)/3, 1e-15) +%! cos(2)/3 - cos(5)/3, 1e-6) ## test different tolerances. %!test @@ -188,4 +190,5 @@ %!error quadl () %!error quadl (@sin) %!error quadl (@sin,1) -%!error <TOL must be a scalar> quadl (@sin, 0, 1, ones (2,2)) +%!error <TOL must be a scalar> quadl (@sin,0,1, ones (2,2)) +%!error <TOL must be .* .=0> quadl (@sin,0,1, -1)
--- a/scripts/general/quadv.m Wed Sep 20 14:45:19 2017 -0700 +++ b/scripts/general/quadv.m Wed Sep 20 17:23:50 2017 -0700 @@ -60,7 +60,7 @@ ## @seealso{quad, quadl, quadgk, quadcc, trapz, dblquad, triplequad} ## @end deftypefn -function [q, nfun] = quadv (f, a, b, tol = [], trace = [], varargin) +function [q, nfun] = quadv (f, a, b, tol = [], trace = false, varargin) if (nargin < 3) print_usage (); @@ -76,9 +76,6 @@ elseif (! isscalar (tol) || tol < 0) error ("quadv: TOL must be a scalar >=0"); endif - if (isempty (trace)) - trace = false; - endif ## Split the interval into 3 abscissa, and apply a 3-point Simpson's rule c = (a + b) / 2; @@ -150,25 +147,26 @@ endfunction -%!assert (quadv (@sin, 0, 2*pi), 0, 1e-5) -%!assert (quadv (@sin, 0, pi), 2, 1e-5) +%!assert (quadv (@sin, 0, 2*pi), 0, 1e-6) +%!assert (quadv (@sin, 0, pi), 2, 1e-6) ## Test weak singularities at the edge %!test %! warning ("off", "Octave:divide-by-zero", "local"); -%! assert (quadv (@(x) 1 ./ sqrt (x), 0, 1), 2, 1e-5); +%! assert (quadv (@(x) 1 ./ sqrt (x), 0, 1), 2, 2e-6); ## Test vector-valued functions -%!assert (quadv (@(x) [(sin (x)), (sin (2 * x))], 0, pi), [2, 0], 1e-5) +%!assert (quadv (@(x) [(sin (x)), (sin (2 * x))], 0, pi), [2, 0], 1e-6) ## Test matrix-valued functions %!test %! warning ("off", "Octave:divide-by-zero", "local"); -%! assert (quadv (@(x) [ x, x, x; x, 1./sqrt(x), x; x, x, x ], 0, 1), -%! [0.5, 0.5, 0.5; 0.5, 2, 0.5; 0.5, 0.5, 0.5], 1e-5); +%! assert (quadv (@(x) [ x,x,x; x,1./sqrt(x),x; x,x,x ], 0, 1), +%! [0.5,0.5,0.5; 0.5,2,0.5; 0.5,0.5,0.5], 2e-6); ## Test input validation %!error quadv () %!error quadv (@sin) %!error quadv (@sin,1) %!error <TOL must be a scalar> quadv (@sin,0,1, ones (2,2)) +%!error <TOL must be .* .=0> quadv (@sin,0,1, -1)