1## Copyright (C) 2008, 2009 David Bateman
3## This file is part of Octave.
5## Octave is free software; you can redistribute it and/or modify it
6## under the terms of the GNU General Public License as published by
7## the Free Software Foundation; either version 3 of the License, or (at
8## your option) any later version.
10## Octave is distributed in the hope that it will be useful, but
11## WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13## General Public License for more details.
15## You should have received a copy of the GNU General Public License
16## along with Octave; see the file COPYING. If not, see
17## <http://www.gnu.org/licenses/>.
20## @deftypefn {Function File} {} dblquad (@var{f}, @var{xa}, @var{xb}, @var{ya}, @var{yb}, @var{tol}, @var{quadf}, @dots{})
21## Numerically evaluate a double integral. The function over with to
22## integrate is defined by @code{@var{f}}, and the interval for the
23## integration is defined by @code{[@var{xa}, @var{xb}, @var{ya},
24## @var{yb}]}. The function @var{f} must accept a vector @var{x} and a
25## scalar @var{y}, and return a vector of the same length as @var{x}.
27## If defined, @var{tol} defines the absolute tolerance to which to
28## which to integrate each sub-integral.
30## Additional arguments, are passed directly to @var{f}. To use the default
31## value for @var{tol} one may pass an empty matrix.
32## @seealso{triplequad, quad, quadv, quadl, quadgk, trapz}
35function q = dblquad(f, xa, xb, ya, yb, tol, quadf, varargin)
39 if (nargin < 6 || isempty (tol))
42 if (nargin < 7 || isempty (quadf))
46 inner = @__dblquad_inner__;
48 f = @(x,y) feval (f, x, y, varargin{:});
52 q = feval (quadf, @(y) inner (y, f, xa, xb, tol, quadf,
53 varargin{:}), ya, yb, tol);
56function q = __dblquad_inner__ (y, f, xa, xb, tol, quadf, varargin)
58 for i = 1 : length (y)
59 q(i) = feval (quadf, @(x) f(x, y(i), varargin{:}), xa, xb, tol);
63%% Nasty integrand to show quadgk off
64%!assert (dblquad (@(x,y) 1 ./ (x+y), 0, 1, 0, 1), 2*log(2), 1e-6)
66%!assert (dblquad (@(x,y) exp(-x.^2 - y.^2) , -1, 1, -1, 1, [], @quadgk), pi * erf(1).^2, 1e-6)
67%!assert (dblquad (@(x,y) exp(-x.^2 - y.^2) , -1, 1, -1, 1, [], @quadl), pi * erf(1).^2, 1e-6)
68%!assert (dblquad (@(x,y) exp(-x.^2 - y.^2) , -1, 1, -1, 1, [], @quadv), pi * erf(1).^2, 1e-6)