annotate scripts/general/quadl.m @ 25003:2365c2661b3c stable

doc: Spellcheck documentation ahead of 4.4 release. * aspell-octave.en.pws: Add new words to Octave-only spelling dictionary. Remove exception words which are no longer used in manual. * basics.txi, bugs.txi, func.txi, geometry.txi, install.txi, matrix.txi, package.txi, plot.txi, poly.txi, preface.txi, quad.txi, sparse.txi, strings.txi, vectorize.txi, data.cc, defaults.cc, file-io.cc, pinv.cc, quadcc.cc, qz.cc, rand.cc, schur.cc, syscalls.cc, sysdep.cc, toplev.cc, amd.cc, audioread.cc, colamd.cc, dmperm.cc, symrcm.cc, quadgk.m, quadl.m, imfinfo.m, rgb2gray.m, javachk.m, usejava.m, unpack.m, fzero.m, glpk.m, pqpnonneg.m, stemleaf.m, print.m, polyfit.m, blackman.m, bicgstab.m, cgs.m, eigs.m, pcg.m, tfqmr.m, gallery.m, rosser.m, toeplitz.m, vander.m, isstrprop.m: Add @nospell{} macro around proper names and other words which aspell should not check. Correct misspellings identified by aspell.
author Rik <rik@octave.org>
date Mon, 26 Mar 2018 10:45:04 -0700
parents d3a507ca2d5d
children 6652d3823428
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
1 ## Copyright (C) 1998-2017 Walter Gautschi
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
2 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
4 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24208
diff changeset
5 ## Octave is free software: you can redistribute it and/or modify it
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24208
diff changeset
7 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
8 ## (at your option) any later version.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
9 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## GNU General Public License for more details.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
14 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24208
diff changeset
17 ## <https://www.gnu.org/licenses/>.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
18
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20689
diff changeset
20 ## @deftypefn {} {@var{q} =} quadl (@var{f}, @var{a}, @var{b})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20689
diff changeset
21 ## @deftypefnx {} {@var{q} =} quadl (@var{f}, @var{a}, @var{b}, @var{tol})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20689
diff changeset
22 ## @deftypefnx {} {@var{q} =} quadl (@var{f}, @var{a}, @var{b}, @var{tol}, @var{trace})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20689
diff changeset
23 ## @deftypefnx {} {@var{q} =} quadl (@var{f}, @var{a}, @var{b}, @var{tol}, @var{trace}, @var{p1}, @var{p2}, @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20689
diff changeset
24 ## @deftypefnx {} {[@var{q}, @var{nfun}] =} quadl (@dots{})
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
25 ##
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
26 ## Numerically evaluate the integral of @var{f} from @var{a} to @var{b} using
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24546
diff changeset
27 ## an adaptive @nospell{Lobatto} rule.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
28 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
29 ## @var{f} is a function handle, inline function, or string containing the name
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
30 ## of the function to evaluate. The function @var{f} must be vectorized and
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
31 ## return a vector of output values when given a vector of input values.
12612
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
32 ##
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
33 ## @var{a} and @var{b} are the lower and upper limits of integration. Both
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
34 ## limits must be finite.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
35 ##
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
36 ## The optional argument @var{tol} defines the absolute tolerance with which
24545
ba8b828ee4f2 doc: Replace @math{1e^{XXX}} sequences with raw 1eXXX (bug #52827).
Rik <rik@octave.org>
parents: 23219
diff changeset
37 ## to perform the integration. The default value is 1e-6.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
38 ##
12612
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
39 ## The algorithm used by @code{quadl} involves recursively subdividing the
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
40 ## integration interval. If @var{trace} is defined then for each subinterval
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
41 ## display: (1) the total number of function evaluations, (2) the left end of
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
42 ## the subinterval, (3) the length of the subinterval, (4) the approximation of
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
43 ## the integral over the subinterval.
12612
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
44 ##
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
45 ## Additional arguments @var{p1}, etc., are passed directly to the function
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
46 ## @var{f}. To use default values for @var{tol} and @var{trace}, one may pass
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
47 ## empty matrices ([]).
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
48 ##
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
49 ## The result of the integration is returned in @var{q}.
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
50 ##
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
51 ## The optional output @var{nfun} indicates the total number of function
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
52 ## evaluations performed.
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
53 ##
19040
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
54 ## Reference: @nospell{W. Gander and W. Gautschi}, @cite{Adaptive Quadrature -
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
55 ## Revisited}, BIT Vol. 40, No. 1, March 2000, pp. 84--101.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
56 ## @url{http://www.inf.ethz.ch/personal/gander/}
24208
eec262017c6a maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 24156
diff changeset
57 ## @seealso{quad, quadv, quadgk, quadcc, trapz, dblquad, triplequad, integral,
24102
c723faa56ab4 Add missing functions integral2.m and integral3.m (bug #52074).
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 24066
diff changeset
58 ## integral2, integral3}
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
59 ## @end deftypefn
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
60
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
61 ## Original Author: Walter Gautschi
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
62 ## Date: 08/03/98
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
63 ## Reference: Gander, Computermathematik, Birkhaeuser, 1992.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
64
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
65 ## 2003-08-05 Shai Ayal
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
66 ## * permission from author to release as GPL
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
67
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
68 function [q, nfun] = quadl (f, a, b, tol = [], trace = false, varargin)
13008
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
69
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
70 if (nargin < 3)
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
71 print_usage ();
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
72 endif
13008
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
73
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
74 if (isa (a, "single") || isa (b, "single"))
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
75 eps = eps ("single");
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
76 else
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
77 eps = eps ("double");
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
78 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
79 if (isempty (tol))
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
80 tol = 1e-6;
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
81 elseif (! isscalar (tol) || tol < 0)
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
82 error ("quadl: TOL must be a scalar >=0");
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
83 elseif (tol < eps)
24066
d9b0d8ae734f Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents: 23220
diff changeset
84 warning ("quadl: TOL specified is smaller than machine precision, using %g",
d9b0d8ae734f Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents: 23220
diff changeset
85 tol);
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
86 tol = eps;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
87 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
88 if (isempty (trace))
13008
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
89 trace = false;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
90 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
91
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
92 y = feval (f, [a, b], varargin{:});
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
93 nfun = 1;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
94
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11562
diff changeset
95 fa = y(1);
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
96 fb = y(2);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
97
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
98 h = b - a;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
99
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
100 [q, nfun, hmin] = adaptlobstp (f, a, b, fa, fb, Inf, nfun, abs (h),
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
101 tol, trace, varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
102
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
103 if (nfun > 10_000)
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
104 warning ("quadl: maximum iteration count reached -- possible singular integral");
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
105 elseif (any (! isfinite (q(:))))
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
106 warning ("quadl: infinite or NaN function evaluations were returned");
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
107 elseif (hmin < (b - a) * eps)
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
108 warning ("quadl: minimum step size reached -- possible singular integral");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
109 endif
13008
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
110
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
111 endfunction
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
112
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
113 function [q, nfun, hmin] = adaptlobstp (f, a, b, fa, fb, q0, nfun, hmin,
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
114 tol, trace, varargin)
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
115 persistent alpha = sqrt (2/3);
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
116 persistent beta = 1 / sqrt (5);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
117
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
118 if (nfun > 10_000)
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
119 q = q0;
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
120 return;
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
121 endif
13008
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
122
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
123 h = (b - a) / 2;
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
124 m = (a + b) / 2;
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
125 mll = m - alpha*h;
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
126 ml = m - beta*h;
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
127 mr = m + beta*h;
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
128 mrr = m + alpha*h;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
129 x = [mll, ml, m, mr, mrr];
13008
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
130 y = feval (f, x, varargin{:});
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
131 nfun += 1;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11562
diff changeset
132 fmll = y(1);
13008
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
133 fml = y(2);
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
134 fm = y(3);
85dac13a911b quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents: 12802
diff changeset
135 fmr = y(4);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
136 fmrr = y(5);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
137 i2 = (h/6)*(fa + fb + 5*(fml+fmr));
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
138 i1 = (h/1470)*(77*(fa+fb) + 432*(fmll+fmrr) + 625*(fml+fmr) + 672*fm);
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
139
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
140 if (abs (b - a) < hmin)
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
141 hmin = abs (b - a);
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
142 endif
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
143
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
144 if (trace)
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
145 disp ([nfun, a, b-a, i1]);
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
146 endif
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
147
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
148 ## Force at least one adaptive step (nfun > 2 test).
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
149 if ((abs (i1-i2) < tol || mll <= a || b <= mrr) && nfun > 2)
12612
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
150 q = i1;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
151 else
24156
ce435b70fd94 quadl.m: Return single output when inputs are single (bug #52243).
Rik <rik@octave.org>
parents: 24102
diff changeset
152 q = zeros (6, 1, class (x));
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
153 [q(1), nfun, hmin] = adaptlobstp (f, a , mll, fa , fmll, q0/6, nfun, hmin,
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
154 tol, trace, varargin{:});
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
155 [q(2), nfun, hmin] = adaptlobstp (f, mll, ml , fmll, fml , q0/6, nfun, hmin,
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
156 tol, trace, varargin{:});
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
157 [q(3), nfun, hmin] = adaptlobstp (f, ml , m , fml , fm , q0/6, nfun, hmin,
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
158 tol, trace, varargin{:});
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
159 [q(4), nfun, hmin] = adaptlobstp (f, m , mr , fm , fmr , q0/6, nfun, hmin,
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
160 tol, trace, varargin{:});
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
161 [q(5), nfun, hmin] = adaptlobstp (f, mr , mrr, fmr , fmrr, q0/6, nfun, hmin,
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
162 tol, trace, varargin{:});
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
163 [q(6), nfun, hmin] = adaptlobstp (f, mrr, b , fmrr, fb , q0/6, nfun, hmin,
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
164 tol, trace, varargin{:});
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
165 q = sum (q);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
166 endif
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
167
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
168 endfunction
12802
412882f498b4 codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents: 12642
diff changeset
169
412882f498b4 codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents: 12642
diff changeset
170
412882f498b4 codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents: 12642
diff changeset
171 ## basic functionality
24066
d9b0d8ae734f Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents: 23220
diff changeset
172 %!assert (quadl (@(x) sin (x), 0, pi), 2, 1e-6)
12802
412882f498b4 codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents: 12642
diff changeset
173
412882f498b4 codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents: 12642
diff changeset
174 ## the values here are very high so it may be unavoidable that this fails
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
175 %!assert (quadl (@(x) sin (3*x).*cosh (x).*sinh (x),10,15, 1e-3),
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
176 %! 2.588424538641647e+10, 1e-3)
12802
412882f498b4 codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents: 12642
diff changeset
177
412882f498b4 codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents: 12642
diff changeset
178 ## extra parameters
412882f498b4 codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents: 12642
diff changeset
179 %!assert (quadl (@(x,a,b) sin (a + b*x), 0, 1, [], [], 2, 3),
24066
d9b0d8ae734f Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents: 23220
diff changeset
180 %! cos(2)/3 - cos(5)/3, 1e-6)
12802
412882f498b4 codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents: 12642
diff changeset
181
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13008
diff changeset
182 ## test different tolerances.
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
183 %!test
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
184 %! [q, nfun1] = quadl (@(x) sin (2 + 3*x).^2, 0, 10, 0.5, []);
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
185 %! assert (q, (60 + sin(4) - sin(64))/12, 0.5);
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
186 %! [q, nfun2] = quadl (@(x) sin (2 + 3*x).^2, 0, 10, 0.1, []);
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
187 %! assert (q, (60 + sin(4) - sin(64))/12, 0.1);
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
188 %! assert (nfun2 > nfun1);
12802
412882f498b4 codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents: 12642
diff changeset
189
24156
ce435b70fd94 quadl.m: Return single output when inputs are single (bug #52243).
Rik <rik@octave.org>
parents: 24102
diff changeset
190 %!test # test single input/output
ce435b70fd94 quadl.m: Return single output when inputs are single (bug #52243).
Rik <rik@octave.org>
parents: 24102
diff changeset
191 %! assert (class (quadl (@sin, 0, 1)), "double");
ce435b70fd94 quadl.m: Return single output when inputs are single (bug #52243).
Rik <rik@octave.org>
parents: 24102
diff changeset
192 %! assert (class (quadl (@sin, single (0), 1)), "single");
ce435b70fd94 quadl.m: Return single output when inputs are single (bug #52243).
Rik <rik@octave.org>
parents: 24102
diff changeset
193 %! assert (class (quadl (@sin, 0, single (1))), "single");
ce435b70fd94 quadl.m: Return single output when inputs are single (bug #52243).
Rik <rik@octave.org>
parents: 24102
diff changeset
194
20689
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
195 ## Test input validation
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
196 %!error quadl ()
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
197 %!error quadl (@sin)
655816377845 quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents: 20231
diff changeset
198 %!error quadl (@sin,1)
24066
d9b0d8ae734f Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents: 23220
diff changeset
199 %!error <TOL must be a scalar> quadl (@sin,0,1, ones (2,2))
d9b0d8ae734f Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents: 23220
diff changeset
200 %!error <TOL must be .* .=0> quadl (@sin,0,1, -1)