3
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3
|
21 |
|
22 */ |
|
23 |
382
|
24 #if !defined (octave_Quad_h) |
|
25 #define octave_Quad_h 1 |
|
26 |
1536
|
27 #include <cfloat> |
|
28 #include <cmath> |
|
29 |
1296
|
30 #include "dColVector.h" |
3
|
31 |
384
|
32 #if !defined (octave_Quad_typedefs) |
|
33 #define octave_Quad_typedefs 1 |
3
|
34 |
|
35 typedef double (*integrand_fcn) (double x); |
|
36 |
|
37 #endif |
|
38 |
260
|
39 // XXX FIXME XXX -- would be nice to not have to have this global |
|
40 // variable. |
|
41 // Nonzero means an error occurred in the calculation of the integrand |
|
42 // function, and the user wants us to quit. |
|
43 extern int quad_integration_error; |
|
44 |
3998
|
45 #include "Quad-opts.h" |
289
|
46 |
1859
|
47 class |
|
48 Quad : public Quad_options |
3
|
49 { |
|
50 public: |
|
51 |
1859
|
52 Quad (integrand_fcn fcn) |
|
53 : Quad_options (), f (fcn) { } |
|
54 |
2425
|
55 virtual ~Quad (void) { } |
2424
|
56 |
1528
|
57 virtual double integrate (void) |
|
58 { |
5275
|
59 octave_idx_type ier, neval; |
1528
|
60 double abserr; |
3511
|
61 return do_integrate (ier, neval, abserr); |
1528
|
62 } |
3
|
63 |
5275
|
64 virtual double integrate (octave_idx_type& ier) |
1528
|
65 { |
5275
|
66 octave_idx_type neval; |
1528
|
67 double abserr; |
3511
|
68 return do_integrate (ier, neval, abserr); |
1528
|
69 } |
|
70 |
5275
|
71 virtual double integrate (octave_idx_type& ier, octave_idx_type& neval) |
1528
|
72 { |
|
73 double abserr; |
3511
|
74 return do_integrate (ier, neval, abserr); |
1528
|
75 } |
|
76 |
5275
|
77 virtual double integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr) |
3511
|
78 { |
|
79 return do_integrate (ier, neval, abserr); |
|
80 } |
|
81 |
5275
|
82 virtual double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr) = 0; |
3
|
83 |
|
84 protected: |
|
85 |
|
86 integrand_fcn f; |
|
87 }; |
|
88 |
1859
|
89 class |
|
90 DefQuad : public Quad |
3
|
91 { |
|
92 public: |
|
93 |
1859
|
94 DefQuad (integrand_fcn fcn) |
|
95 : Quad (fcn), lower_limit (0.0), upper_limit (1.0), singularities () { } |
1528
|
96 |
1859
|
97 DefQuad (integrand_fcn fcn, double ll, double ul) |
|
98 : Quad (fcn), lower_limit (ll), upper_limit (ul), singularities () { } |
1528
|
99 |
|
100 DefQuad (integrand_fcn fcn, double ll, double ul, |
1859
|
101 const ColumnVector& sing) |
|
102 : Quad (fcn), lower_limit (ll), upper_limit (ul), |
|
103 singularities (sing) { } |
1528
|
104 |
1859
|
105 DefQuad (integrand_fcn fcn, const ColumnVector& sing) |
|
106 : Quad (fcn), lower_limit (0.0), upper_limit (1.0), |
|
107 singularities (sing) { } |
1528
|
108 |
2424
|
109 ~DefQuad (void) { } |
|
110 |
5275
|
111 double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); |
3
|
112 |
|
113 private: |
|
114 |
|
115 double lower_limit; |
|
116 double upper_limit; |
|
117 |
1528
|
118 ColumnVector singularities; |
3
|
119 }; |
|
120 |
1859
|
121 class |
|
122 IndefQuad : public Quad |
3
|
123 { |
|
124 public: |
|
125 |
|
126 enum IntegralType { bound_to_inf, neg_inf_to_bound, doubly_infinite }; |
|
127 |
1859
|
128 IndefQuad (integrand_fcn fcn) |
|
129 : Quad (fcn), bound (0.0), type (bound_to_inf) { } |
1528
|
130 |
1859
|
131 IndefQuad (integrand_fcn fcn, double b, IntegralType t) |
|
132 : Quad (fcn), bound (b), type (t) { } |
1528
|
133 |
2424
|
134 ~IndefQuad (void) { } |
|
135 |
5275
|
136 double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); |
3
|
137 |
|
138 private: |
|
139 |
|
140 double bound; |
|
141 IntegralType type; |
1859
|
142 int integration_error; |
3
|
143 }; |
|
144 |
|
145 #endif |
|
146 |
|
147 /* |
|
148 ;;; Local Variables: *** |
|
149 ;;; mode: C++ *** |
|
150 ;;; End: *** |
|
151 */ |