Mercurial > octave
changeset 30995:1fcfe9443917
quadgk.m: Don't warn about failing to converge if second output ERR is requested (bug #62412)
* quadgk.m: Document change in behavior (using the same language as for
quadcc). Check number of outputs is less than 2 before issuing warning about
failed convergence. Re-code BIST test not to issue a warning about using
deprecated "inline" function. Add BIST test for bug #62412.
* quadcc.cc (Fquadcc): Make BIST test for bug #62412 a fixed, regression
if it fails. Change error bounds on test to be default relative tolerance.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 11 May 2022 11:54:57 -0700 |
parents | 1212ed22f962 |
children | 4298af839d20 |
files | libinterp/corefcn/quadcc.cc scripts/general/quadgk.m |
diffstat | 2 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/quadcc.cc Wed May 11 09:45:31 2022 -0700 +++ b/libinterp/corefcn/quadcc.cc Wed May 11 11:54:57 2022 -0700 @@ -2251,11 +2251,11 @@ %! assert (class (quadcc (@sin, 0, single (1))), "single"); %! assert (class (quadcc (@sin, single (0), single (1))), "single"); -%!test<62412> +%!test <*62412> %! f = @(t) -1 ./ t.^1.1; %! fail ("quadcc (f, 1, Inf)", "warning", "Error tolerance not met"); %! [q, err] = quadcc (f, 1, Inf); -%! assert (err > 1); +%! assert (err > 1e-5); ## Test input validation %!error quadcc ()
--- a/scripts/general/quadgk.m Wed May 11 09:45:31 2022 -0700 +++ b/scripts/general/quadgk.m Wed May 11 11:54:57 2022 -0700 @@ -123,7 +123,12 @@ ## ## @var{err} is an approximate bound on the error in the integral ## @w{@code{abs (@var{q} - @var{I})}}, where @var{I} is the exact value of the -## integral. +## integral. If the adaptive integration did not converge, the value of +## @var{err} will be larger than the requested tolerance. If only a single +## output is requested then a warning will be emitted when the requested +## tolerance is not met. If the second output @var{err} is requested then no +## warning is issued and it is the responsibility of the programmer to inspect +## and determine whether the results are satisfactory. ## ## Reference: @nospell{L.F. Shampine}, ## @cite{"Vectorized adaptive quadrature in @sc{matlab}"}, Journal of @@ -400,7 +405,7 @@ [q_subs, q_errs] = __quadgk_eval__ (f, subs, eps1, trans); endwhile - if (err > max (abstol, reltol * abs (q))) + if (nargout < 2 && err > max (abstol, reltol * abs (q))) warning (warn_id, "quadgk: Error tolerance not met. Estimated error %g", err); endif @@ -469,7 +474,9 @@ %!assert (quadgk (@sin,-pi,pi), 0, 1e-10) -%!assert (quadgk (inline ("sin"),-pi,pi), 0, 1e-10) +%!test +%! warning ("off", "Octave:legacy-function", "local"); +%! 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) @@ -495,6 +502,12 @@ %! f = @(x) x .^ 5 .* exp (-x) .* sin (x); %! assert (quadgk (f, 0, Inf, "RelTol", 1e-8, "AbsTol", 1e-12), -15, -1e-8); +%!test <*62412> +%! f = @(t) -1 ./ t.^1.1; +%! fail ("quadgk (f, 1, Inf)", "warning", "Error tolerance not met"); +%! [q, err] = quadgk (f, 1, Inf); +%! assert (err > 1e-5); + ## Test input validation %!error quadgk (@sin) %!error quadgk (@sin, 0)