Mercurial > hg > octave-lyh
comparison scripts/general/triplequad.m @ 12612:16cca721117b stable
doc: Update all documentation for chapter on Numerical Integration
* cumtrapz.m, dblquad.m, quadgk.m, quadl.m, quadv.m, trapz.m,
triplequad.m, quad.cc, quadcc.cc: Improve docstrings.
* Quad-opts.in: Keep code sample together on a single line.
* mk-opts.pl: Update quad-options function description
* octave.texi: Update order of detailmenu to match order in quad.texi.
* quad.txi: Add language about when to use each quad function,
add examples of using trapz.
* aspell-octave.en.pws: Add new spelling words from quad.texi chapter
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 17 Apr 2011 19:57:07 -0700 |
parents | d0b799dafede |
children | 0713ad019e53 f96b9b9f141b |
comparison
equal
deleted
inserted
replaced
12607:2846ea58b288 | 12612:16cca721117b |
---|---|
15 ## You should have received a copy of the GNU General Public License | 15 ## You should have received a copy of the GNU General Public License |
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} triplequad (@var{f}, @var{xa}, @var{xb}, @var{ya}, @var{yb}, @var{za}, @var{zb}, @var{tol}, @var{quadf}, @dots{}) | 20 ## @deftypefn {Function File} {} triplequad (@var{f}, @var{xa}, @var{xb}, @var{ya}, @var{yb}, @var{za}, @var{zb}) |
21 ## Numerically evaluate a triple integral. The function over which to | 21 ## @deftypefnx {Function File} {} triplequad (@var{f}, @var{xa}, @var{xb}, @var{ya}, @var{yb}, @var{za}, @var{zb}, @var{tol}) |
22 ## integrate is defined by @code{@var{f}}, and the interval for the | 22 ## @deftypefnx {Function File} {} triplequad (@var{f}, @var{xa}, @var{xb}, @var{ya}, @var{yb}, @var{za}, @var{zb}, @var{tol}, @var{quadf}) |
23 ## integration is defined by @code{[@var{xa}, @var{xb}, @var{ya}, | 23 ## @deftypefnx {Function File} {} triplequad (@var{f}, @var{xa}, @var{xb}, @var{ya}, @var{yb}, @var{za}, @var{zb}, @var{tol}, @var{quadf}, @dots{}) |
24 ## @var{yb}, @var{za}, @var{zb}]}. The function @var{f} must accept a | 24 ## Numerically evaluate the triple integral of @var{f}. |
25 ## vector @var{x} and a scalar @var{y}, and return a vector of the same | 25 ## @var{f} is a function handle, inline function, or string |
26 ## length as @var{x}. | 26 ## containing the name of the function to evaluate. The function @var{f} must |
27 ## have the form @math{w = f(x,y,z)} where either @var{x} or @var{y} is a | |
28 ## vector and the remaining inputs are scalars. It should return a vector of | |
29 ## the same length and orientation as @var{x} or @var{y}. | |
27 ## | 30 ## |
28 ## If defined, @var{tol} defines the absolute tolerance to which to | 31 ## @var{xa}, @var{ya}, @var{za} and @var{xb}, @var{yb}, @var{zb} are the lower |
29 ## which to integrate each sub-integral. | 32 ## and upper limits of integration for x, y, and z respectively. The |
33 ## underlying integrator determines whether infinite bounds are accepted. | |
34 ## | |
35 ## The optional argument @var{tol} defines the absolute tolerance used to | |
36 ## integrate each sub-integral. The default value is @math{1e^{-6}}. | |
37 ## | |
38 ## The optional argument @var{quadf} specifies which underlying integrator | |
39 ## function to use. Any choice but @code{quad} is available and the default | |
40 ## is @code{quadgk}. | |
30 ## | 41 ## |
31 ## Additional arguments, are passed directly to @var{f}. To use the default | 42 ## Additional arguments, are passed directly to @var{f}. To use the default |
32 ## value for @var{tol} one may pass an empty matrix. | 43 ## value for @var{tol} or @var{quadf} one may pass an empty matrix ([]). |
33 ## @seealso{dblquad, quad, quadv, quadl, quadgk, quadcc, trapz} | 44 ## @seealso{dblquad, quad, quadv, quadl, quadgk, quadcc, trapz} |
34 ## @end deftypefn | 45 ## @end deftypefn |
35 | 46 |
36 function Q = triplequad(f, xa, xb, ya, yb, za, zb, tol, quadf, varargin) | 47 function q = triplequad(f, xa, xb, ya, yb, za, zb, tol, quadf, varargin) |
37 if (nargin < 7) | 48 if (nargin < 7) |
38 print_usage (); | 49 print_usage (); |
39 endif | 50 endif |
40 if (nargin < 8 || isempty (tol)) | 51 if (nargin < 8 || isempty (tol)) |
41 tol = 1e-6; | 52 tol = 1e-6; |
48 if (ischar (f)) | 59 if (ischar (f)) |
49 f = @(x,y,z) feval (f, x, y, z, varargin{:}); | 60 f = @(x,y,z) feval (f, x, y, z, varargin{:}); |
50 varargin = {}; | 61 varargin = {}; |
51 endif | 62 endif |
52 | 63 |
53 Q = dblquad(@(y, z) inner (y, z, f, xa, xb, tol, quadf, varargin{:}),ya, yb, za, zb, tol); | 64 q = dblquad(@(y, z) inner (y, z, f, xa, xb, tol, quadf, varargin{:}),ya, yb, za, zb, tol); |
54 endfunction | 65 endfunction |
55 | 66 |
56 function Q = __triplequad_inner__ (y, z, f, xa, xb, tol, quadf, varargin) | 67 function q = __triplequad_inner__ (y, z, f, xa, xb, tol, quadf, varargin) |
57 Q = zeros (size(y)); | 68 q = zeros (size(y)); |
58 for i = 1 : length (y) | 69 for i = 1 : length (y) |
59 Q(i) = feval (quadf, @(x) f (x, y(i), z, varargin{:}), xa, xb, tol); | 70 q(i) = feval (quadf, @(x) f (x, y(i), z, varargin{:}), xa, xb, tol); |
60 endfor | 71 endfor |
61 endfunction | 72 endfunction |
62 | 73 |
63 %% These tests are too expensive to run normally. Disable them | 74 %% These tests are too expensive to run normally. Disable them |
64 % !#assert (triplequad (@(x,y,z) exp(-x.^2 - y.^2 - z.^2) , -1, 1, -1, 1, -1, 1, [], @quadgk), pi ^ (3/2) * erf(1).^3, 1e-6) | 75 % !#assert (triplequad (@(x,y,z) exp(-x.^2 - y.^2 - z.^2) , -1, 1, -1, 1, -1, 1, [], @quadgk), pi ^ (3/2) * erf(1).^3, 1e-6) |
65 % !#assert (triplequad (@(x,y,z) exp(-x.^2 - y.^2 - z.^2) , -1, 1, -1, 1, -1, 1, [], @quadl), pi ^ (3/2) * erf(1).^3, 1e-6) | 76 % !#assert (triplequad (@(x,y,z) exp(-x.^2 - y.^2 - z.^2) , -1, 1, -1, 1, -1, 1, [], @quadl), pi ^ (3/2) * erf(1).^3, 1e-6) |
66 % !#assert (triplequad (@(x,y,z) exp(-x.^2 - y.^2 - z.^2) , -1, 1, -1, 1, -1, 1, [], @quadv), pi ^ (3/2) * erf(1).^3, 1e-6) | 77 % !#assert (triplequad (@(x,y,z) exp(-x.^2 - y.^2 - z.^2) , -1, 1, -1, 1, -1, 1, [], @quadv), pi ^ (3/2) * erf(1).^3, 1e-6) |
78 |