3
|
1 /* |
|
2 |
1859
|
3 Copyright (C) 1996 John W. Eaton |
3
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
3
|
20 |
|
21 */ |
|
22 |
382
|
23 #if !defined (octave_Quad_h) |
|
24 #define octave_Quad_h 1 |
|
25 |
1296
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
3
|
29 |
1536
|
30 #include <cfloat> |
|
31 #include <cmath> |
|
32 |
1296
|
33 #include "dColVector.h" |
3
|
34 |
384
|
35 #if !defined (octave_Quad_typedefs) |
|
36 #define octave_Quad_typedefs 1 |
3
|
37 |
|
38 typedef double (*integrand_fcn) (double x); |
|
39 |
|
40 #endif |
|
41 |
260
|
42 // XXX FIXME XXX -- would be nice to not have to have this global |
|
43 // variable. |
|
44 // Nonzero means an error occurred in the calculation of the integrand |
|
45 // function, and the user wants us to quit. |
|
46 extern int quad_integration_error; |
|
47 |
1859
|
48 class |
|
49 Quad_options |
289
|
50 { |
|
51 public: |
|
52 |
1528
|
53 Quad_options (void) { init (); } |
|
54 |
1859
|
55 // XXX FIXME XXX -- check for invalid values? |
1528
|
56 Quad_options (double abs, double rel) |
1859
|
57 : x_absolute_tolerance (abs), x_relative_tolerance (rel) { } |
1528
|
58 |
1859
|
59 Quad_options (const Quad_options& opt) |
|
60 : x_absolute_tolerance (opt.x_absolute_tolerance), |
|
61 x_relative_tolerance (opt.x_relative_tolerance) { } |
289
|
62 |
1528
|
63 Quad_options& operator = (const Quad_options& opt) |
|
64 { |
|
65 if (this != &opt) |
1873
|
66 set_options (opt); |
|
67 |
1528
|
68 return *this; |
|
69 } |
|
70 |
|
71 ~Quad_options (void) { } |
289
|
72 |
1528
|
73 void init (void) |
|
74 { |
1859
|
75 double sqrt_eps = ::sqrt (DBL_EPSILON); |
|
76 |
1528
|
77 x_absolute_tolerance = sqrt_eps; |
|
78 x_relative_tolerance = sqrt_eps; |
|
79 } |
289
|
80 |
1528
|
81 void set_default_options (void) { init (); } |
|
82 |
1873
|
83 void set_options (const Quad_options& opt) |
|
84 { |
|
85 x_absolute_tolerance = opt.x_absolute_tolerance; |
|
86 x_relative_tolerance = opt.x_relative_tolerance; |
|
87 } |
|
88 |
1859
|
89 // XXX FIXME XXX -- check for invalid values? |
|
90 void set_absolute_tolerance (double val) { x_absolute_tolerance = val; } |
|
91 void set_relative_tolerance (double val) { x_relative_tolerance = val; } |
1528
|
92 |
|
93 double absolute_tolerance (void) { return x_absolute_tolerance; } |
|
94 double relative_tolerance (void) { return x_relative_tolerance; } |
289
|
95 |
|
96 private: |
|
97 |
|
98 double x_absolute_tolerance; |
|
99 double x_relative_tolerance; |
|
100 }; |
|
101 |
1859
|
102 class |
|
103 Quad : public Quad_options |
3
|
104 { |
|
105 public: |
|
106 |
1859
|
107 Quad (integrand_fcn fcn) |
|
108 : Quad_options (), f (fcn) { } |
|
109 |
1528
|
110 Quad (integrand_fcn fcn, double abs, double rel) |
1859
|
111 : Quad_options (abs, rel), f (fcn) { } |
1528
|
112 |
|
113 virtual double integrate (void) |
|
114 { |
|
115 int ier, neval; |
|
116 double abserr; |
|
117 return integrate (ier, neval, abserr); |
|
118 } |
3
|
119 |
1528
|
120 virtual double integrate (int& ier) |
|
121 { |
|
122 int neval; |
|
123 double abserr; |
|
124 return integrate (ier, neval, abserr); |
|
125 } |
|
126 |
|
127 virtual double integrate (int& ier, int& neval) |
|
128 { |
|
129 double abserr; |
|
130 return integrate (ier, neval, abserr); |
|
131 } |
|
132 |
3
|
133 virtual double integrate (int& ier, int& neval, double& abserr) = 0; |
|
134 |
|
135 protected: |
|
136 |
|
137 integrand_fcn f; |
|
138 }; |
|
139 |
1859
|
140 class |
|
141 DefQuad : public Quad |
3
|
142 { |
|
143 public: |
|
144 |
1859
|
145 DefQuad (integrand_fcn fcn) |
|
146 : Quad (fcn), lower_limit (0.0), upper_limit (1.0), singularities () { } |
1528
|
147 |
1859
|
148 DefQuad (integrand_fcn fcn, double ll, double ul) |
|
149 : Quad (fcn), lower_limit (ll), upper_limit (ul), singularities () { } |
1528
|
150 |
|
151 DefQuad (integrand_fcn fcn, double ll, double ul, double abs, |
1859
|
152 double rel) |
|
153 : Quad (fcn, abs, rel), lower_limit (ll), upper_limit (ul), |
|
154 singularities () { } |
1528
|
155 |
|
156 DefQuad (integrand_fcn fcn, double ll, double ul, |
1859
|
157 const ColumnVector& sing) |
|
158 : Quad (fcn), lower_limit (ll), upper_limit (ul), |
|
159 singularities (sing) { } |
1528
|
160 |
|
161 DefQuad (integrand_fcn fcn, const ColumnVector& sing, double abs, |
1859
|
162 double rel) |
|
163 : Quad (fcn, abs, rel), lower_limit (0.0), upper_limit (1.0), |
|
164 singularities (sing) { } |
1528
|
165 |
1859
|
166 DefQuad (integrand_fcn fcn, const ColumnVector& sing) |
|
167 : Quad (fcn), lower_limit (0.0), upper_limit (1.0), |
|
168 singularities (sing) { } |
1528
|
169 |
|
170 DefQuad (integrand_fcn fcn, double ll, double ul, const ColumnVector& sing, |
1859
|
171 double abs, double rel) |
|
172 : Quad (fcn, abs, rel), lower_limit (ll), upper_limit (ul), |
|
173 singularities (sing) { } |
3
|
174 |
|
175 double integrate (int& ier, int& neval, double& abserr); |
|
176 |
|
177 private: |
|
178 |
|
179 double lower_limit; |
|
180 double upper_limit; |
|
181 |
1528
|
182 ColumnVector singularities; |
3
|
183 }; |
|
184 |
1859
|
185 class |
|
186 IndefQuad : public Quad |
3
|
187 { |
|
188 public: |
|
189 |
|
190 enum IntegralType { bound_to_inf, neg_inf_to_bound, doubly_infinite }; |
|
191 |
1859
|
192 IndefQuad (integrand_fcn fcn) |
|
193 : Quad (fcn), bound (0.0), type (bound_to_inf) { } |
1528
|
194 |
1859
|
195 IndefQuad (integrand_fcn fcn, double b, IntegralType t) |
|
196 : Quad (fcn), bound (b), type (t) { } |
1528
|
197 |
3
|
198 IndefQuad (integrand_fcn fcn, double b, IntegralType t, double abs, |
1859
|
199 double rel) |
|
200 : Quad (fcn, abs, rel), bound (b), type (t) { } |
1528
|
201 |
1859
|
202 IndefQuad (integrand_fcn fcn, double abs, double rel) |
|
203 : Quad (fcn, abs, rel), bound (0.0), type (bound_to_inf) { } |
3
|
204 |
|
205 double integrate (int& ier, int& neval, double& abserr); |
|
206 |
|
207 private: |
|
208 |
|
209 double bound; |
|
210 IntegralType type; |
1859
|
211 int integration_error; |
3
|
212 }; |
|
213 |
|
214 #endif |
|
215 |
|
216 /* |
|
217 ;;; Local Variables: *** |
|
218 ;;; mode: C++ *** |
|
219 ;;; End: *** |
|
220 */ |