Mercurial > octave
annotate scripts/general/quadl.m @ 33639:65b1cf6aa60a bytecode-interpreter tip
maint: Merge default to bytecode-interpreter
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Mon, 03 Jun 2024 14:38:47 -0400 |
parents | 2e484f9f1f18 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 ## Copyright (C) 1998-2024 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27800
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
5837 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24208
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
5837 | 11 ## 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
|
12 ## 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
|
13 ## (at your option) any later version. |
5837 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
5837 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## 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
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
5837 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20689
diff
changeset
|
27 ## @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
|
28 ## @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
|
29 ## @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
|
30 ## @deftypefnx {} {@var{q} =} quadl (@var{f}, @var{a}, @var{b}, @var{tol}, @var{trace}, @var{p1}, @var{p2}, @dots{}) |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
31 ## @deftypefnx {} {[@var{q}, @var{nfev}] =} quadl (@dots{}) |
5837 | 32 ## |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
33 ## 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
|
34 ## 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
|
35 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
36 ## @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
|
37 ## 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
|
38 ## 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
|
39 ## |
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
40 ## @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
|
41 ## limits must be finite. |
5837 | 42 ## |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
43 ## 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
|
44 ## to perform the integration. The default value is 1e-6. |
5837 | 45 ## |
12612
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
46 ## 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
|
47 ## 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
|
48 ## 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
|
49 ## 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
|
50 ## 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
|
51 ## |
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
52 ## 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
|
53 ## @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
|
54 ## empty matrices ([]). |
5837 | 55 ## |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
56 ## 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
|
57 ## |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
58 ## The optional output @var{nfev} indicates the total number of function |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
59 ## evaluations performed. |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
60 ## |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 ## Reference: @nospell{W. Gander and W. Gautschi}, @cite{Adaptive Quadrature - |
27800
5a6a19a4e3da
doc: Use Texinfo non-sentence ending periods in citations.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
62 ## Revisited}, BIT Vol.@: 40, No.@: 1, March 2000, pp.@: 84--101. |
25143
13fd0610480f
doc: Use https whenever possible in @url entries.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
63 ## @url{https://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
|
64 ## @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
|
65 ## integral2, integral3} |
5837 | 66 ## @end deftypefn |
67 | |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
68 ## Original Author: Walter Gautschi |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
69 ## Date: 08/03/98 |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
70 ## Reference: Gander, Computermathematik, Birkhaeuser, 1992. |
5837 | 71 |
72 ## 2003-08-05 Shai Ayal | |
73 ## * permission from author to release as GPL | |
74 | |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
75 function [q, nfev] = 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
|
76 |
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
77 if (nargin < 3) |
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
78 print_usage (); |
5837 | 79 endif |
13008
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
80 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
81 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
|
82 eps = eps ("single"); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
83 else |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
84 eps = eps ("double"); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
85 endif |
5838 | 86 if (isempty (tol)) |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
87 tol = 1e-6; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
88 elseif (! isscalar (tol) || tol < 0) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
89 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
|
90 elseif (tol < eps) |
24066
d9b0d8ae734f
Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
91 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
|
92 tol); |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
93 tol = eps; |
5837 | 94 endif |
5838 | 95 if (isempty (trace)) |
13008
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
96 trace = false; |
5837 | 97 endif |
98 | |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
99 y = feval (f, [a, b], varargin{:}); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
100 nfev = 1; |
5838 | 101 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11562
diff
changeset
|
102 fa = y(1); |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
103 fb = y(2); |
5838 | 104 |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
105 h = b - a; |
5838 | 106 |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
107 [q, nfev, hmin] = adaptlobstp (f, a, b, fa, fb, Inf, nfev, abs (h), |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
108 tol, trace, varargin{:}); |
5838 | 109 |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
110 if (nfev > 10_000) |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
111 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
|
112 elseif (any (! isfinite (q(:)))) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
113 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
|
114 elseif (hmin < (b - a) * eps) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
115 warning ("quadl: minimum step size reached -- possible singular integral"); |
5837 | 116 endif |
13008
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
117 |
5837 | 118 endfunction |
119 | |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
120 function [q, nfev, hmin] = adaptlobstp (f, a, b, fa, fb, q0, nfev, hmin, |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
121 tol, trace, varargin) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
122 |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
123 persistent alpha = sqrt (2/3); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
124 persistent beta = 1 / sqrt (5); |
5837 | 125 |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
126 if (nfev > 10_000) |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
127 q = q0; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
128 return; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
129 endif |
13008
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
130 |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
131 h = (b - a) / 2; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
132 m = (a + b) / 2; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
133 mll = m - alpha*h; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
134 ml = m - beta*h; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
135 mr = m + beta*h; |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
136 mrr = m + alpha*h; |
5838 | 137 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
|
138 y = feval (f, x, varargin{:}); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
139 nfev += 1; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11562
diff
changeset
|
140 fmll = y(1); |
13008
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
141 fml = y(2); |
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
142 fm = y(3); |
85dac13a911b
quadl.m: Fix integration with large error tolerances (Bug #33792)
Rik <octave@nomad.inbox5.com>
parents:
12802
diff
changeset
|
143 fmr = y(4); |
5837 | 144 fmrr = y(5); |
5838 | 145 i2 = (h/6)*(fa + fb + 5*(fml+fmr)); |
146 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
|
147 |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
148 if (abs (b - a) < hmin) |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
149 hmin = abs (b - a); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
150 endif |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
151 |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
152 if (trace) |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
153 disp ([nfev, a, b-a, i1]); |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
154 endif |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
155 |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
156 ## Force at least one adaptive step (nfev > 2 test). |
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
157 if ((abs (i1-i2) < tol || mll <= a || b <= mrr) && nfev > 2) |
12612
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
158 q = i1; |
5837 | 159 else |
24156
ce435b70fd94
quadl.m: Return single output when inputs are single (bug #52243).
Rik <rik@octave.org>
parents:
24102
diff
changeset
|
160 q = zeros (6, 1, class (x)); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
161 [q(1), nfev, hmin] = adaptlobstp (f, a , mll, fa , fmll, q0/6, nfev, hmin, |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
162 tol, trace, varargin{:}); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
163 [q(2), nfev, hmin] = adaptlobstp (f, mll, ml , fmll, fml , q0/6, nfev, hmin, |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
164 tol, trace, varargin{:}); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
165 [q(3), nfev, hmin] = adaptlobstp (f, ml , m , fml , fm , q0/6, nfev, hmin, |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
166 tol, trace, varargin{:}); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
167 [q(4), nfev, hmin] = adaptlobstp (f, m , mr , fm , fmr , q0/6, nfev, hmin, |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
168 tol, trace, varargin{:}); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
169 [q(5), nfev, hmin] = adaptlobstp (f, mr , mrr, fmr , fmrr, q0/6, nfev, hmin, |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
170 tol, trace, varargin{:}); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
171 [q(6), nfev, hmin] = adaptlobstp (f, mrr, b , fmrr, fb , q0/6, nfev, hmin, |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
172 tol, trace, varargin{:}); |
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
173 q = sum (q); |
5837 | 174 endif |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
175 |
5837 | 176 endfunction |
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 |
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
179 ## basic functionality |
24066
d9b0d8ae734f
Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
180 %!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
|
181 |
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
182 ## 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
|
183 %!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
|
184 %! 2.588424538641647e+10, 1e-3) |
12802
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
185 |
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
186 ## extra parameters |
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
187 %!assert (quadl (@(x,a,b) sin (a + b*x), 0, 1, [], [], 2, 3), |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
188 %! 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
|
189 |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
13008
diff
changeset
|
190 ## test different tolerances. |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
191 %!test |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
192 %! [q, nfev1] = quadl (@(x) sin (2 + 3*x).^2, 0, 10, 0.5, []); |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
193 %! assert (q, (60 + sin (4) - sin (64))/12, 0.5); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
194 %! [q, nfev2] = quadl (@(x) sin (2 + 3*x).^2, 0, 10, 0.1, []); |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
195 %! assert (q, (60 + sin (4) - sin (64))/12, 0.1); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
196 %! assert (nfev2 > nfev1); |
12802
412882f498b4
codesprint: Wrote 5 tests for quadl.m
David Wells <drwells@vt.edu>
parents:
12642
diff
changeset
|
197 |
24156
ce435b70fd94
quadl.m: Return single output when inputs are single (bug #52243).
Rik <rik@octave.org>
parents:
24102
diff
changeset
|
198 %!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
|
199 %! 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
|
200 %! 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
|
201 %! 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
|
202 |
20689
655816377845
quadl.m: Overhal function and switch to absolute tolerance.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
203 ## Test input validation |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
204 %!error <Invalid call> quadl () |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
205 %!error <Invalid call> quadl (@sin) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
206 %!error <Invalid call> quadl (@sin,1) |
24066
d9b0d8ae734f
Update tolerances in BIST tests for quad functions.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
207 %!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
|
208 %!error <TOL must be .* .=0> quadl (@sin,0,1, -1) |