Mercurial > octave
annotate scripts/general/quadl.m @ 24066:d9b0d8ae734f
Update tolerances in BIST tests for quad functions.
* quadgk.m: Use 1e-10 for absolute tolerances or -1e-6 for relative tolerances
in assert statements.
* quadl.m: Print a warning when Octave overrides users specified tolerance with
eps. Use 1e-6 for absolute tolerances. Add new BIST test.
* quadv.m: Set default value of "trace" input to false in function prototype.
Ues 1e-6 for absolute tolerances. Add new BIST test.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 20 Sep 2017 17:23:50 -0700 |
parents | 092078913d54 |
children | c723faa56ab4 |
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 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
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 | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
8 ## (at your option) any later version. |
5837 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
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 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5837 | 18 |
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 | 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 |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
27 ## an adaptive Lobatto rule. |
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 | 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 |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
37 ## to perform the integration. The default value is @math{1e-6}. |
5837 | 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 | 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 | 56 ## @url{http://www.inf.ethz.ch/personal/gander/} |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
57 ## @seealso{quad, quadv, quadgk, quadcc, trapz, dblquad, triplequad} |
5837 | 58 ## @end deftypefn |
59 | |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
60 ## Original Author: Walter Gautschi |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
61 ## Date: 08/03/98 |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
62 ## Reference: Gander, Computermathematik, Birkhaeuser, 1992. |
5837 | 63 |
64 ## 2003-08-05 Shai Ayal | |
65 ## * permission from author to release as GPL | |
66 | |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
67 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
|
68 |
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
69 if (nargin < 3) |
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
70 print_usage (); |
5837 | 71 endif |
13008
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
72 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
73 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
|
74 eps = eps ("single"); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
75 else |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
76 eps = eps ("double"); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
77 endif |
5838 | 78 if (isempty (tol)) |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
79 tol = 1e-6; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
80 elseif (! isscalar (tol) || tol < 0) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
81 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
|
82 elseif (tol < eps) |
24066
d9b0d8ae734f
Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
83 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
|
84 tol); |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
85 tol = eps; |
5837 | 86 endif |
5838 | 87 if (isempty (trace)) |
13008
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
88 trace = false; |
5837 | 89 endif |
90 | |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
91 y = feval (f, [a, b], varargin{:}); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
92 nfun = 1; |
5838 | 93 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11562
diff
changeset
|
94 fa = y(1); |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
95 fb = y(2); |
5838 | 96 |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
97 h = b - a; |
5838 | 98 |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
99 [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
|
100 tol, trace, varargin{:}); |
5838 | 101 |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
102 if (nfun > 10_000) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
103 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
|
104 elseif (any (! isfinite (q(:)))) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
105 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
|
106 elseif (hmin < (b - a) * eps) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
107 warning ("quadl: minimum step size reached -- possible singular integral"); |
5837 | 108 endif |
13008
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
109 |
5837 | 110 endfunction |
111 | |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
112 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
|
113 tol, trace, varargin) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
114 persistent alpha = sqrt (2/3); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
115 persistent beta = 1 / sqrt (5); |
5837 | 116 |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
117 if (nfun > 10_000) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
118 q = q0; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
119 return; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
120 endif |
13008
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
121 |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
122 h = (b - a) / 2; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
123 m = (a + b) / 2; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
124 mll = m - alpha*h; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
125 ml = m - beta*h; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
126 mr = m + beta*h; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
127 mrr = m + alpha*h; |
5838 | 128 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
|
129 y = feval (f, x, varargin{:}); |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
130 nfun += 1; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11562
diff
changeset
|
131 fmll = y(1); |
13008
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
132 fml = y(2); |
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
133 fm = y(3); |
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
134 fmr = y(4); |
5837 | 135 fmrr = y(5); |
5838 | 136 i2 = (h/6)*(fa + fb + 5*(fml+fmr)); |
137 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
|
138 |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
139 if (abs (b - a) < hmin) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
140 hmin = abs (b - a); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
141 endif |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
142 |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
143 if (trace) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
144 disp ([nfun, a, b-a, i1]); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
145 endif |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
146 |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
147 ## 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
|
148 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
|
149 q = i1; |
5837 | 150 else |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
151 q = zeros (6, 1); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
152 [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
|
153 tol, trace, varargin{:}); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
154 [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
|
155 tol, trace, varargin{:}); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
156 [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
|
157 tol, trace, varargin{:}); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
158 [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
|
159 tol, trace, varargin{:}); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
160 [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
|
161 tol, trace, varargin{:}); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
162 [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
|
163 tol, trace, varargin{:}); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
164 q = sum (q); |
5837 | 165 endif |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
166 |
5837 | 167 endfunction |
12802
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
168 |
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 ## basic functionality |
24066
d9b0d8ae734f
Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
171 %!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
|
172 |
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
173 ## 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
|
174 %!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
|
175 %! 2.588424538641647e+10, 1e-3) |
12802
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
176 |
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
177 ## extra parameters |
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
178 %!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
|
179 %! 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
|
180 |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
13008
diff
changeset
|
181 ## test different tolerances. |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
182 %!test |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
183 %! [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
|
184 %! 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
|
185 %! [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
|
186 %! 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
|
187 %! assert (nfun2 > nfun1); |
12802
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
188 |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
189 ## Test input validation |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
190 %!error quadl () |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
191 %!error quadl (@sin) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
192 %!error quadl (@sin,1) |
24066
d9b0d8ae734f
Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
193 %!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
|
194 %!error <TOL must be .* .=0> quadl (@sin,0,1, -1) |