Mercurial > hg > octave-nkf
annotate liboctave/Quad.h @ 8924:3c3cbe8f18e0 ss-3-1-54
bump version info for snapshot
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 13:28:03 -0500 |
parents | eb63fbe60fab |
children | 4c0cdbe0acca |
rev | line source |
---|---|
3 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, |
8920 | 4 2006, 2007, 2008 John W. Eaton |
3 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
3 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
3 | 21 |
22 */ | |
23 | |
382 | 24 #if !defined (octave_Quad_h) |
25 #define octave_Quad_h 1 | |
26 | |
1536 | 27 #include <cfloat> |
28 | |
1296 | 29 #include "dColVector.h" |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
30 #include "fColVector.h" |
7231 | 31 #include "lo-math.h" |
3 | 32 |
384 | 33 #if !defined (octave_Quad_typedefs) |
34 #define octave_Quad_typedefs 1 | |
3 | 35 |
36 typedef double (*integrand_fcn) (double x); | |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
37 typedef float (*float_integrand_fcn) (float x); |
3 | 38 |
39 #endif | |
40 | |
5775 | 41 // FIXME -- would be nice to not have to have this global |
260 | 42 // variable. |
43 // Nonzero means an error occurred in the calculation of the integrand | |
44 // function, and the user wants us to quit. | |
6108 | 45 extern OCTAVE_API int quad_integration_error; |
260 | 46 |
3998 | 47 #include "Quad-opts.h" |
289 | 48 |
1859 | 49 class |
6108 | 50 OCTAVE_API |
1859 | 51 Quad : public Quad_options |
3 | 52 { |
53 public: | |
54 | |
1859 | 55 Quad (integrand_fcn fcn) |
56 : Quad_options (), f (fcn) { } | |
57 | |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
58 Quad (float_integrand_fcn fcn) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
59 : Quad_options (), ff (fcn) { } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
60 |
2425 | 61 virtual ~Quad (void) { } |
2424 | 62 |
1528 | 63 virtual double integrate (void) |
64 { | |
5275 | 65 octave_idx_type ier, neval; |
1528 | 66 double abserr; |
3511 | 67 return do_integrate (ier, neval, abserr); |
1528 | 68 } |
3 | 69 |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
70 virtual float float_integrate (void) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
71 { |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
72 octave_idx_type ier, neval; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
73 float abserr; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
74 return do_integrate (ier, neval, abserr); |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
75 } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
76 |
5275 | 77 virtual double integrate (octave_idx_type& ier) |
1528 | 78 { |
5275 | 79 octave_idx_type neval; |
1528 | 80 double abserr; |
3511 | 81 return do_integrate (ier, neval, abserr); |
1528 | 82 } |
83 | |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
84 virtual float float_integrate (octave_idx_type& ier) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
85 { |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
86 octave_idx_type neval; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
87 float abserr; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
88 return do_integrate (ier, neval, abserr); |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
89 } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
90 |
5275 | 91 virtual double integrate (octave_idx_type& ier, octave_idx_type& neval) |
1528 | 92 { |
93 double abserr; | |
3511 | 94 return do_integrate (ier, neval, abserr); |
1528 | 95 } |
96 | |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
97 virtual float float_integrate (octave_idx_type& ier, octave_idx_type& neval) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
98 { |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
99 float abserr; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
100 return do_integrate (ier, neval, abserr); |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
101 } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
102 |
5275 | 103 virtual double integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr) |
3511 | 104 { |
105 return do_integrate (ier, neval, abserr); | |
106 } | |
107 | |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
108 virtual float float_integrate (octave_idx_type& ier, octave_idx_type& neval, float& abserr) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
109 { |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
110 return do_integrate (ier, neval, abserr); |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
111 } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
112 |
5275 | 113 virtual double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr) = 0; |
3 | 114 |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
115 virtual float do_integrate (octave_idx_type& ier, octave_idx_type& neval, float& abserr) = 0; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
116 |
3 | 117 protected: |
118 | |
119 integrand_fcn f; | |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
120 float_integrand_fcn ff; |
3 | 121 }; |
122 | |
1859 | 123 class |
6108 | 124 OCTAVE_API |
1859 | 125 DefQuad : public Quad |
3 | 126 { |
127 public: | |
128 | |
1859 | 129 DefQuad (integrand_fcn fcn) |
130 : Quad (fcn), lower_limit (0.0), upper_limit (1.0), singularities () { } | |
1528 | 131 |
1859 | 132 DefQuad (integrand_fcn fcn, double ll, double ul) |
133 : Quad (fcn), lower_limit (ll), upper_limit (ul), singularities () { } | |
1528 | 134 |
135 DefQuad (integrand_fcn fcn, double ll, double ul, | |
1859 | 136 const ColumnVector& sing) |
137 : Quad (fcn), lower_limit (ll), upper_limit (ul), | |
138 singularities (sing) { } | |
1528 | 139 |
1859 | 140 DefQuad (integrand_fcn fcn, const ColumnVector& sing) |
141 : Quad (fcn), lower_limit (0.0), upper_limit (1.0), | |
142 singularities (sing) { } | |
1528 | 143 |
2424 | 144 ~DefQuad (void) { } |
145 | |
5275 | 146 double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); |
3 | 147 |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
148 float do_integrate (octave_idx_type& ier, octave_idx_type& neval, float& abserr); |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
149 |
3 | 150 private: |
151 | |
152 double lower_limit; | |
153 double upper_limit; | |
154 | |
1528 | 155 ColumnVector singularities; |
3 | 156 }; |
157 | |
1859 | 158 class |
6108 | 159 OCTAVE_API |
1859 | 160 IndefQuad : public Quad |
3 | 161 { |
162 public: | |
163 | |
164 enum IntegralType { bound_to_inf, neg_inf_to_bound, doubly_infinite }; | |
165 | |
1859 | 166 IndefQuad (integrand_fcn fcn) |
167 : Quad (fcn), bound (0.0), type (bound_to_inf) { } | |
1528 | 168 |
1859 | 169 IndefQuad (integrand_fcn fcn, double b, IntegralType t) |
170 : Quad (fcn), bound (b), type (t) { } | |
1528 | 171 |
2424 | 172 ~IndefQuad (void) { } |
173 | |
5275 | 174 double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); |
3 | 175 |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
176 float do_integrate (octave_idx_type& ier, octave_idx_type& neval, float& abserr); |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
177 |
3 | 178 private: |
179 | |
180 double bound; | |
181 IntegralType type; | |
1859 | 182 int integration_error; |
3 | 183 }; |
184 | |
7805
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
185 class |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
186 OCTAVE_API |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
187 FloatDefQuad : public Quad |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
188 { |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
189 public: |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
190 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
191 FloatDefQuad (float_integrand_fcn fcn) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
192 : Quad (fcn), lower_limit (0.0), upper_limit (1.0), singularities () { } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
193 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
194 FloatDefQuad (float_integrand_fcn fcn, float ll, float ul) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
195 : Quad (fcn), lower_limit (ll), upper_limit (ul), singularities () { } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
196 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
197 FloatDefQuad (float_integrand_fcn fcn, float ll, float ul, |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
198 const FloatColumnVector& sing) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
199 : Quad (fcn), lower_limit (ll), upper_limit (ul), |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
200 singularities (sing) { } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
201 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
202 FloatDefQuad (float_integrand_fcn fcn, const FloatColumnVector& sing) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
203 : Quad (fcn), lower_limit (0.0), upper_limit (1.0), |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
204 singularities (sing) { } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
205 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
206 ~FloatDefQuad (void) { } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
207 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
208 double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
209 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
210 float do_integrate (octave_idx_type& ier, octave_idx_type& neval, float& abserr); |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
211 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
212 private: |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
213 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
214 float lower_limit; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
215 float upper_limit; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
216 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
217 FloatColumnVector singularities; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
218 }; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
219 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
220 class |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
221 OCTAVE_API |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
222 FloatIndefQuad : public Quad |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
223 { |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
224 public: |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
225 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
226 enum IntegralType { bound_to_inf, neg_inf_to_bound, doubly_infinite }; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
227 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
228 FloatIndefQuad (float_integrand_fcn fcn) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
229 : Quad (fcn), bound (0.0), type (bound_to_inf) { } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
230 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
231 FloatIndefQuad (float_integrand_fcn fcn, double b, IntegralType t) |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
232 : Quad (fcn), bound (b), type (t) { } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
233 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
234 ~FloatIndefQuad (void) { } |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
235 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
236 double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
237 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
238 float do_integrate (octave_idx_type& ier, octave_idx_type& neval, float& abserr); |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
239 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
240 private: |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
241 |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
242 float bound; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
243 IntegralType type; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
244 int integration_error; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
245 }; |
62affb34e648
Make quad work with single precision
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
246 |
3 | 247 #endif |
248 | |
249 /* | |
250 ;;; Local Variables: *** | |
251 ;;; mode: C++ *** | |
252 ;;; End: *** | |
253 */ |