Mercurial > octave
annotate libinterp/corefcn/quad.cc @ 20725:7164a69472dd
eliminate more uses of error state
* daspk.cc, dasrt.cc, dassl.cc, lsode.cc, quad.cc: Eliminate uses of
error_state. Handle user-supplied functions consistently.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 19 Nov 2015 15:46:40 -0500 |
parents | 7b608fadc663 |
children | 200ae1d650b7 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18862
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2928 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2928 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2928 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <string> | |
28 | |
3567 | 29 #include <iomanip> |
3523 | 30 #include <iostream> |
2928 | 31 |
32 #include "Quad.h" | |
33 #include "lo-mappers.h" | |
34 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
35 #include "defun.h" |
2928 | 36 #include "error.h" |
37 #include "gripes.h" | |
38 #include "pager.h" | |
39 #include "oct-obj.h" | |
2968 | 40 #include "ov-fcn.h" |
3243 | 41 #include "unwind-prot.h" |
2928 | 42 #include "utils.h" |
43 #include "variables.h" | |
44 | |
3998 | 45 #include "Quad-opts.cc" |
46 | |
2928 | 47 #if defined (quad) |
48 #undef quad | |
49 #endif | |
50 | |
51 // Global pointer for user defined function required by quadrature functions. | |
2968 | 52 static octave_function *quad_fcn; |
2928 | 53 |
4140 | 54 // Have we warned about imaginary values returned from user function? |
55 static bool warned_imaginary = false; | |
56 | |
3243 | 57 // Is this a recursive call? |
58 static int call_depth = 0; | |
59 | |
2928 | 60 double |
61 quad_user_function (double x) | |
62 { | |
63 double retval = 0.0; | |
64 | |
65 octave_value_list args; | |
66 args(0) = x; | |
67 | |
68 if (quad_fcn) | |
69 { | |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
70 octave_value_list tmp; |
2928 | 71 |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
72 try |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
73 { |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
74 tmp = quad_fcn->do_multi_index_op (1, args); |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
75 } |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
76 catch (const octave_execution_exception&) |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
77 { |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
78 gripe_user_supplied_eval ("quad"); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
79 throw; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
80 } |
2928 | 81 |
82 if (tmp.length () && tmp(0).is_defined ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
83 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
84 if (! warned_imaginary && tmp(0).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
85 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
86 warning ("quad: ignoring imaginary part returned from user-supplied function"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
87 warned_imaginary = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
88 } |
4140 | 89 |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
90 retval = tmp(0).xdouble_value ("quad: expecting user supplied function to return numeric value"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
91 } |
2928 | 92 else |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
93 gripe_user_supplied_eval ("quad"); |
2928 | 94 } |
95 | |
96 return retval; | |
97 } | |
98 | |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
99 float |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
100 quad_float_user_function (float x) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
101 { |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
102 float retval = 0.0; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
103 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
104 octave_value_list args; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
105 args(0) = x; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
106 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
107 if (quad_fcn) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
108 { |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
109 octave_value_list tmp; |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
110 |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
111 try |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
112 { |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
113 tmp = quad_fcn->do_multi_index_op (1, args); |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
114 } |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
115 catch (const octave_execution_exception&) |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
116 { |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
117 gripe_user_supplied_eval ("quad"); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
118 throw; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
119 } |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
120 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
121 if (tmp.length () && tmp(0).is_defined ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
122 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
123 if (! warned_imaginary && tmp(0).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
124 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
125 warning ("quad: ignoring imaginary part returned from user-supplied function"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
126 warned_imaginary = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
127 } |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
128 |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
129 retval = tmp(0).xfloat_value ("quad: expecting user supplied function to return numeric value"); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
130 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
131 } |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
132 else |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
133 gripe_user_supplied_eval ("quad"); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
134 } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
135 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
136 return retval; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
137 } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
138 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
139 DEFUN (quad, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
140 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
141 @deftypefn {Built-in Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
142 @deftypefnx {Built-in Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b}, @var{tol})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
143 @deftypefnx {Built-in Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b}, @var{tol}, @var{sing})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
144 @deftypefnx {Built-in Function} {[@var{q}, @var{ier}, @var{nfun}, @var{err}] =} quad (@dots{})\n\ |
12612
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
145 Numerically evaluate the integral of @var{f} from @var{a} to @var{b} using\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
146 Fortran routines from @w{@sc{quadpack}}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
147 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
148 @var{f} is a function handle, inline function, or a string containing the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
149 name of the function to evaluate. The function must have the form @code{y =\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
150 f (x)} where @var{y} and @var{x} are scalars.\n\ |
2928 | 151 \n\ |
12612
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
152 @var{a} and @var{b} are the lower and upper limits of integration. Either\n\ |
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
153 or both may be infinite.\n\ |
2928 | 154 \n\ |
3368 | 155 The optional argument @var{tol} is a vector that specifies the desired\n\ |
2928 | 156 accuracy of the result. The first element of the vector is the desired\n\ |
157 absolute tolerance, and the second element is the desired relative\n\ | |
3368 | 158 tolerance. To choose a relative test only, set the absolute\n\ |
159 tolerance to zero. To choose an absolute test only, set the relative\n\ | |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
160 tolerance to zero. Both tolerances default to @code{sqrt (eps)} or\n\ |
12612
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
161 approximately @math{1.5e^{-8}}.\n\ |
2928 | 162 \n\ |
163 The optional argument @var{sing} is a vector of values at which the\n\ | |
3368 | 164 integrand is known to be singular.\n\ |
165 \n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
166 The result of the integration is returned in @var{q}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
167 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
168 @var{ier} contains an integer error code (0 indicates a successful\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
169 integration).\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
170 \n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
171 @var{nfun} indicates the number of function evaluations that were\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
172 made.\n\ |
3964 | 173 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
174 @var{err} contains an estimate of the error in the solution.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
175 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
176 The function @code{quad_options} can set other optional parameters for\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
177 @code{quad}.\n\ |
6741 | 178 \n\ |
12612
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
179 Note: because @code{quad} is written in Fortran it cannot be called\n\ |
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
180 recursively. This prevents its use in integrating over more than one\n\ |
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
181 variable by routines @code{dblquad} and @code{triplequad}.\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11562
diff
changeset
|
182 @seealso{quad_options, quadv, quadl, quadgk, quadcc, trapz, dblquad, triplequad}\n\ |
3368 | 183 @end deftypefn") |
2928 | 184 { |
185 octave_value_list retval; | |
186 | |
4954 | 187 std::string fcn_name; |
188 | |
4140 | 189 warned_imaginary = false; |
190 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
191 unwind_protect frame; |
3243 | 192 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
193 frame.protect_var (call_depth); |
3243 | 194 call_depth++; |
195 | |
196 if (call_depth > 1) | |
20709
a2a99aaf680b
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
197 error ("quad: invalid recursive call"); |
3243 | 198 |
2928 | 199 int nargin = args.length (); |
200 | |
3243 | 201 if (nargin > 2 && nargin < 6 && nargout < 5) |
202 { | |
4954 | 203 if (args(0).is_function_handle () || args(0).is_inline_function ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
204 quad_fcn = args(0).function_value (); |
4954 | 205 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
206 { |
18862
6825522c25e4
maint: Use names beginning and ending with "__" for internal only functions.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
207 fcn_name = unique_symbol_name ("__quad_fcn__"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
208 std::string fname = "function y = "; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
209 fname.append (fcn_name); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
210 fname.append ("(x) y = "); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
211 quad_fcn = extract_function (args(0), "quad", fcn_name, fname, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
212 "; endfunction"); |
20709
a2a99aaf680b
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
213 frame.add_fcn (clear_function, fcn_name); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
214 } |
4954 | 215 |
3243 | 216 if (! quad_fcn) |
20709
a2a99aaf680b
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
217 error ("quad: FCN argument is not a valid function name or handle"); |
3243 | 218 |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
219 if (args(1).is_single_type () || args(2).is_single_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
220 { |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
221 float a = args(1).xfloat_value ("quad: lower limit of integration A must be a scalar"); |
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
222 float b = args(2).xfloat_value ("quad: upper limit of integration B must be a scalar"); |
3243 | 223 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
224 int indefinite = 0; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
225 FloatIndefQuad::IntegralType indef_type |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
226 = FloatIndefQuad::doubly_infinite; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
227 float bound = 0.0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
228 if (xisinf (a) && xisinf (b)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
229 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
230 indefinite = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
231 indef_type = FloatIndefQuad::doubly_infinite; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
232 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
233 else if (xisinf (a)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
234 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
235 indefinite = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
236 bound = b; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
237 indef_type = FloatIndefQuad::neg_inf_to_bound; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
238 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
239 else if (xisinf (b)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
240 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
241 indefinite = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
242 bound = a; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
243 indef_type = FloatIndefQuad::bound_to_inf; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
244 } |
3243 | 245 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
246 octave_idx_type ier = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
247 octave_idx_type nfun = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
248 float abserr = 0.0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
249 float val = 0.0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
250 bool have_sing = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
251 FloatColumnVector sing; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
252 FloatColumnVector tol; |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
253 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
254 switch (nargin) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
255 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
256 case 5: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
257 if (indefinite) |
20709
a2a99aaf680b
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
258 error ("quad: singularities not allowed on infinite intervals"); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
259 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
260 have_sing = true; |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
261 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
262 sing = args(4).xfloat_vector_value ("quad: fifth argument SING must be a vector vector of singularities"); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
263 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
264 case 4: |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
265 tol = args(3).xfloat_vector_value ("quad: TOL must be a 1 or 2-element vector"); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
266 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
267 switch (tol.numel ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
268 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
269 case 2: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
270 quad_opts.set_single_precision_relative_tolerance (tol (1)); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
271 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
272 case 1: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
273 quad_opts.set_single_precision_absolute_tolerance (tol (0)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
274 break; |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
275 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
276 default: |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
277 error ("quad: TOL must be a 1 or 2-element vector"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
278 } |
3243 | 279 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
280 case 3: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
281 if (indefinite) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
282 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
283 FloatIndefQuad iq (quad_float_user_function, bound, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
284 indef_type); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
285 iq.set_options (quad_opts); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
286 val = iq.float_integrate (ier, nfun, abserr); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
287 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
288 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
289 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
290 if (have_sing) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
291 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
292 FloatDefQuad dq (quad_float_user_function, a, b, sing); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
293 dq.set_options (quad_opts); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
294 val = dq.float_integrate (ier, nfun, abserr); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
295 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
296 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
297 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
298 FloatDefQuad dq (quad_float_user_function, a, b); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
299 dq.set_options (quad_opts); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
300 val = dq.float_integrate (ier, nfun, abserr); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
301 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
302 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
303 break; |
3243 | 304 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
305 default: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
306 panic_impossible (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
307 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
308 } |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
309 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
310 retval(3) = abserr; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
311 retval(2) = nfun; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
312 retval(1) = ier; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
313 retval(0) = val; |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
314 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
315 } |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
316 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
317 { |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
318 double a = args(1).xdouble_value ("quad: lower limit of integration A must be a scalar"); |
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
319 double b = args(2).xdouble_value ("quad: upper limit of integration B must be a scalar"); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
320 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
321 int indefinite = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
322 IndefQuad::IntegralType indef_type = IndefQuad::doubly_infinite; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
323 double bound = 0.0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
324 if (xisinf (a) && xisinf (b)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
325 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
326 indefinite = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
327 indef_type = IndefQuad::doubly_infinite; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
328 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
329 else if (xisinf (a)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
330 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
331 indefinite = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
332 bound = b; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
333 indef_type = IndefQuad::neg_inf_to_bound; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
334 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
335 else if (xisinf (b)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
336 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
337 indefinite = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
338 bound = a; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
339 indef_type = IndefQuad::bound_to_inf; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
340 } |
3243 | 341 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
342 octave_idx_type ier = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
343 octave_idx_type nfun = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
344 double abserr = 0.0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
345 double val = 0.0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
346 bool have_sing = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
347 ColumnVector sing; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
348 ColumnVector tol; |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
349 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
350 switch (nargin) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
351 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
352 case 5: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
353 if (indefinite) |
20709
a2a99aaf680b
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
354 error ("quad: singularities not allowed on infinite intervals"); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
355 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
356 have_sing = true; |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
357 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
358 sing = args(4).vector_value ("quad: fifth argument SING must be a vector vector of singularities"); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
359 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
360 case 4: |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
361 tol = args(3).xvector_value ("quad: TOL must be a 1 or 2-element vector"); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
362 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
363 switch (tol.numel ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
364 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
365 case 2: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
366 quad_opts.set_relative_tolerance (tol (1)); |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
367 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
368 case 1: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
369 quad_opts.set_absolute_tolerance (tol (0)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
370 break; |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
371 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
372 default: |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
373 error ("quad: TOL must be a 1 or 2-element vector"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
374 } |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
375 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
376 case 3: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
377 if (indefinite) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
378 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
379 IndefQuad iq (quad_user_function, bound, indef_type); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
380 iq.set_options (quad_opts); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
381 val = iq.integrate (ier, nfun, abserr); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
382 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
383 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
384 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
385 if (have_sing) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
386 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
387 DefQuad dq (quad_user_function, a, b, sing); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
388 dq.set_options (quad_opts); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
389 val = dq.integrate (ier, nfun, abserr); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
390 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
391 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
392 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
393 DefQuad dq (quad_user_function, a, b); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
394 dq.set_options (quad_opts); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
395 val = dq.integrate (ier, nfun, abserr); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
396 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
397 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
398 break; |
3243 | 399 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
400 default: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
401 panic_impossible (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
402 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
403 } |
3243 | 404 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
405 retval(3) = abserr; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
406 retval(2) = nfun; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
407 retval(1) = ier; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
408 retval(0) = val; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
409 } |
4954 | 410 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
411 if (fcn_name.length ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
412 clear_function (fcn_name); |
3243 | 413 } |
414 else | |
5823 | 415 print_usage (); |
2928 | 416 |
417 return retval; | |
418 } | |
419 | |
420 /* | |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
421 %!function y = __f (x) |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
422 %! y = x + 1; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
423 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
424 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
425 %!test |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
426 %! [v, ier, nfun, err] = quad ("__f", 0, 5); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
427 %! assert (ier, 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
428 %! assert (v, 17.5, sqrt (eps)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
429 %! assert (nfun > 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
430 %! assert (err < sqrt (eps)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
431 |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
432 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
433 %! [v, ier, nfun, err] = quad ("__f", single (0), single (5)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
434 %! assert (ier, 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
435 %! assert (v, 17.5, sqrt (eps ("single"))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
436 %! assert (nfun > 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
437 %! assert (err < sqrt (eps ("single"))); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
438 |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
439 %!function y = __f (x) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
440 %! y = x .* sin (1 ./ x) .* sqrt (abs (1 - x)); |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
441 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
442 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
443 %!test |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
444 %! [v, ier, nfun, err] = quad ("__f", 0.001, 3); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
445 %! assert (ier == 0 || ier == 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
446 %! assert (v, 1.98194120273598, sqrt (eps)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
447 %! assert (nfun > 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
448 |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
449 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
450 %! [v, ier, nfun, err] = quad ("__f", single (0.001), single (3)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
451 %! assert (ier == 0 || ier == 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
452 %! assert (v, 1.98194120273598, sqrt (eps ("single"))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
453 %! assert (nfun > 0); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
454 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
455 %!error quad () |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
456 %!error quad ("__f", 1, 2, 3, 4, 5) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
457 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
458 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
459 %! quad_options ("absolute tolerance", eps); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
460 %! assert (quad_options ("absolute tolerance") == eps); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
461 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
462 %!error quad_options (1, 2, 3) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
463 */ |