# HG changeset patch
# User Nicholas R. Jankowski <jankowskin@asme.org>
# Date 1505924339 14400
#      Wed Sep 20 12:18:59 2017 -0400
# Node ID bf4f033eafb2cce67359ee1aef7295a3d980f722
# Parent  d8e2fffb371cf0958d3e1c26cb3334cb946023ec
integral.m: enable default tolerances, code cleanup, update BISTs (bug #50604)

* scripts/general/integral.m: integral enforces default abstol and reltol. 
  Removes mention of lower default tolerance for single valued inputs from help 
  text. BISTS updated to include single input/output compatibility and edited 
  test throwing singularity warnings, plus some spacing corrections.

diff -r d8e2fffb371c -r bf4f033eafb2 scripts/general/integral.m
--- a/scripts/general/integral.m	Tue Sep 19 22:01:09 2017 -0700
+++ b/scripts/general/integral.m	Wed Sep 20 12:18:59 2017 -0400
@@ -44,11 +44,11 @@
 ## @table @code
 ## @item AbsTol
 ## Define the absolute error tolerance for the quadrature.  The default
-## absolute tolerance is 1e-10 (1e-5 for single).
+## absolute tolerance is 1e-10.
 ##
 ## @item RelTol
 ## Define the relative error tolerance for the quadrature.  The default
-## relative tolerance is 1e-6 (1e-4 for single).
+## relative tolerance is 1e-6.
 ##
 ## @item Waypoints
 ## Specifies points to be used in defining subintervals of the quadrature
@@ -109,21 +109,29 @@
       endswitch
     endwhile
 
+    
+    ## set default tolerance values if not otherwise specified
+    if (isempty (reltol))
+      reltol = 1e-6;
+    
+    elseif (arrayvalued)
+      ## FIXME: remove warning once we have reltol compatible arrayval'd
+      ## quad or other array compatible way of calling quadgk.
+      warning(["integral: array-valued quadrature currently only accepts", ...
+               " AbsTol. RelTol ignored."]);
+    endif
+
+    if (isempty (abstol))
+      abstol = 1e-10;
+    endif
+        
     if (arrayvalued)
-      ## FIXME: replace warning with arrayfun(?) call to quadgk
+      ## FIXME: replace warning with array compatible call to quadgk
       if (! isempty (waypoints))
         warning(["integral: array-valued quadrature routine currently ", ...
                  "unable to handle WayPoints.  WayPoints are ignored."]);
       endif
 
-      ## FIXME: remove warning once we have reltol compatible arrayval'd
-      ## quad or arrayfun call to quadgk.
-      if (! isempty (reltol))
-        warning(["integral: array-valued quadrature only accepts AbsTol.", ...
-                 "  RelTol ignored."]);
-      endif
-
-      ## quadv accepts empty abstol input.
       q = quadv (f, a, b, abstol);
 
     else
@@ -175,10 +183,10 @@
 
 %!assert (integral (@sin,-pi,0), -2, 1e-6);
 %!assert (integral (@sin,0,pi), 2, 1e-6);
-%!assert (integral (@(x) 1./sqrt (x),0,1), 2, 1e-6);
-%!assert (integral (@(x) abs (1 - x.^2),0,2, "Waypoints", 1), 2, 1e-6);
+%!assert (integral (@(x) 1./sqrt (x), 0, 1), 2, 1e-6);
+%!assert (integral (@(x) abs (1 - x.^2), 0, 2, "Waypoints", 1), 2, 1e-6);
 %!assert (integral (@(x) 1./(sqrt (x) .* (x+1)),0,Inf), pi, 1e-6);
-%!assert (integral (@(z) log (z),1+i,1+i, "WayPoints", [1-i, -1,-i, -1+i]), ...
+%!assert (integral (@(z) log (z), 1+i, 1+i, "WayPoints", [1-i, -1,-i, -1+i]),...
 %!        -pi * 1i, 1e-6);
 %!assert (integral (@(x) exp (-x .^ 2),-Inf,Inf), sqrt (pi), 1e-6);
 %!assert (integral (@(x) exp (-x .^ 2),-Inf,0), sqrt (pi)/2, 1e-6);
@@ -190,10 +198,21 @@
 
 ## Test matrix-valued functions
 %!test
-%! warning ("off", "Octave:divide-by-zero", "local");
-%! assert (integral (@(x) [x, x, x; x, 1./sqrt(x), x; x, x, x], 0, 1, ...
+%! assert (integral (@(x) [x, x, x; x, exp(x), x; x, x, x], 0, 1, ...
 %!                   "ArrayValued", 1), ...
-%!         [0.5, 0.5, 0.5; 0.5, 2, 0.5; 0.5, 0.5, 0.5], 1e-5);
+%!         [0.5, 0.5, 0.5; 0.5, (exp (1) - 1), 0.5; 0.5, 0.5, 0.5], 1e-10);
+
+## Test single handling and compatibility (not tolerances)
+%!assert (integral (@(x) x, 0, single (2)), single (2), 1e-10);
+%!assert (integral (@(x) x, single (0), 2), single (2), 1e-10);
+%!assert (integral (@(x) x, single (0), single (2)), single (2), 1e-10);
+%!assert (integral (@(x) single (x), 0, 2), single (2), 1e-10);
+%!assert (integral (@(x) double (x), 0, single (2)), single (2), 1e-10);
+%!assert (integral (@(x) double (x), single (0), 2), single (2), 1e-10);
+%!assert (integral (@(x) x, 0, 2, "AbsTol", single (1e-5)), double (2), 1e-10);
+%!assert (integral (@(x) x, 0, 2, "RelTol", single (1e-5)), double (2), 1e-10);
+%!assert (integral (@(x) abs (1 - x.^2), 0, 2, "Waypoints", single (1)), ...
+%!         single (2), 1e-6);
 
 ## Test input validation
 %!error integral (@sin)
