changeset 13850:64ab148fcbb9

quadv.m: Fixes for convergence issues with vector-valued functions (patch #7627)
author Alexander Klein <alexander.klein@math.uni-giessen.de>
date Wed, 09 Nov 2011 15:06:39 -0500
parents b4b8e525dee0
children 372869056e0f
files scripts/general/quadv.m
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/quadv.m	Wed Nov 09 17:53:23 2011 -0800
+++ b/scripts/general/quadv.m	Wed Nov 09 15:06:39 2011 -0500
@@ -1,5 +1,8 @@
 ## Copyright (C) 2008-2011 David Bateman
 ##
+## Fixes for convergence issues with vector-valued functions:
+## (C) 2011 Alexander Klein <alexander.klein@math.uni-giessen.de>
+##
 ## This file is part of Octave.
 ##
 ## Octave is free software; you can redistribute it and/or modify it
@@ -15,6 +18,8 @@
 ## You should have received a copy of the GNU General Public License
 ## along with Octave; see the file COPYING.  If not, see
 ## <http://www.gnu.org/licenses/>.
+##
+## TODO: Make norm for convergence testing configurable
 
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {@var{q} =} quadv (@var{f}, @var{a}, @var{b})
@@ -88,10 +93,10 @@
 
   ## If have edge singularities, move edge point by eps*(b-a) as
   ## discussed in Shampine paper used to implement quadgk
-  if (isinf (fa))
+  if ( any( isinf( vec(fa))))
     fa = feval (f, a + myeps * (b-a), varargin{:});
   endif
-  if (isinf (fb))
+  if ( any( isinf( vec (fb))))
     fb = feval (f, b - myeps * (b-a), varargin{:});
   endif
 
@@ -103,7 +108,7 @@
 
   if (nfun > 10000)
     warning ("maximum iteration count reached");
-  elseif (isnan (q) || isinf (q))
+  elseif (any(vec(isnan (q) || isinf (q))))
     warning ("infinite or NaN function evaluations were returned");
   elseif (hmin < (b - a) * myeps)
     warning ("minimum step size reached -- possibly singular integral");
@@ -133,7 +138,9 @@
     endif
 
     ## Force at least one adpative step.
-    if (nfun == 5 || abs (q - q0) > tol)
+    ## Not vectorizing q-q0 in the norm provides a more rigid criterion for
+    ## matrix-valued functions.
+    if (nfun == 5 || norm (q - q0, Inf) > tol)
       [q1, nfun, hmin] = simpsonstp (f, a, c, d, fa, fc, fd, q1, nfun, hmin,
                                     tol, trace, varargin{:});
       [q2, nfun, hmin] = simpsonstp (f, c, b, e, fc, fb, fe, q2, nfun, hmin,
@@ -152,3 +159,5 @@
 %% Handles vector-valued functions
 %!assert (quadv (@(x) [(sin (x)), (sin (2 * x))], 0, pi), [2, 0], 1e-5)
 
+%% Handles matrix-valued functions
+%!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)