3
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, |
|
4 2006, 2007 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" |
7231
|
30 #include "lo-math.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 |
5775
|
39 // FIXME -- would be nice to not have to have this global |
260
|
40 // variable. |
|
41 // Nonzero means an error occurred in the calculation of the integrand |
|
42 // function, and the user wants us to quit. |
6108
|
43 extern OCTAVE_API int quad_integration_error; |
260
|
44 |
3998
|
45 #include "Quad-opts.h" |
289
|
46 |
1859
|
47 class |
6108
|
48 OCTAVE_API |
1859
|
49 Quad : public Quad_options |
3
|
50 { |
|
51 public: |
|
52 |
1859
|
53 Quad (integrand_fcn fcn) |
|
54 : Quad_options (), f (fcn) { } |
|
55 |
2425
|
56 virtual ~Quad (void) { } |
2424
|
57 |
1528
|
58 virtual double integrate (void) |
|
59 { |
5275
|
60 octave_idx_type ier, neval; |
1528
|
61 double abserr; |
3511
|
62 return do_integrate (ier, neval, abserr); |
1528
|
63 } |
3
|
64 |
5275
|
65 virtual double integrate (octave_idx_type& ier) |
1528
|
66 { |
5275
|
67 octave_idx_type neval; |
1528
|
68 double abserr; |
3511
|
69 return do_integrate (ier, neval, abserr); |
1528
|
70 } |
|
71 |
5275
|
72 virtual double integrate (octave_idx_type& ier, octave_idx_type& neval) |
1528
|
73 { |
|
74 double abserr; |
3511
|
75 return do_integrate (ier, neval, abserr); |
1528
|
76 } |
|
77 |
5275
|
78 virtual double integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr) |
3511
|
79 { |
|
80 return do_integrate (ier, neval, abserr); |
|
81 } |
|
82 |
5275
|
83 virtual double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr) = 0; |
3
|
84 |
|
85 protected: |
|
86 |
|
87 integrand_fcn f; |
|
88 }; |
|
89 |
1859
|
90 class |
6108
|
91 OCTAVE_API |
1859
|
92 DefQuad : public Quad |
3
|
93 { |
|
94 public: |
|
95 |
1859
|
96 DefQuad (integrand_fcn fcn) |
|
97 : Quad (fcn), lower_limit (0.0), upper_limit (1.0), singularities () { } |
1528
|
98 |
1859
|
99 DefQuad (integrand_fcn fcn, double ll, double ul) |
|
100 : Quad (fcn), lower_limit (ll), upper_limit (ul), singularities () { } |
1528
|
101 |
|
102 DefQuad (integrand_fcn fcn, double ll, double ul, |
1859
|
103 const ColumnVector& sing) |
|
104 : Quad (fcn), lower_limit (ll), upper_limit (ul), |
|
105 singularities (sing) { } |
1528
|
106 |
1859
|
107 DefQuad (integrand_fcn fcn, const ColumnVector& sing) |
|
108 : Quad (fcn), lower_limit (0.0), upper_limit (1.0), |
|
109 singularities (sing) { } |
1528
|
110 |
2424
|
111 ~DefQuad (void) { } |
|
112 |
5275
|
113 double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); |
3
|
114 |
|
115 private: |
|
116 |
|
117 double lower_limit; |
|
118 double upper_limit; |
|
119 |
1528
|
120 ColumnVector singularities; |
3
|
121 }; |
|
122 |
1859
|
123 class |
6108
|
124 OCTAVE_API |
1859
|
125 IndefQuad : public Quad |
3
|
126 { |
|
127 public: |
|
128 |
|
129 enum IntegralType { bound_to_inf, neg_inf_to_bound, doubly_infinite }; |
|
130 |
1859
|
131 IndefQuad (integrand_fcn fcn) |
|
132 : Quad (fcn), bound (0.0), type (bound_to_inf) { } |
1528
|
133 |
1859
|
134 IndefQuad (integrand_fcn fcn, double b, IntegralType t) |
|
135 : Quad (fcn), bound (b), type (t) { } |
1528
|
136 |
2424
|
137 ~IndefQuad (void) { } |
|
138 |
5275
|
139 double do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr); |
3
|
140 |
|
141 private: |
|
142 |
|
143 double bound; |
|
144 IntegralType type; |
1859
|
145 int integration_error; |
3
|
146 }; |
|
147 |
|
148 #endif |
|
149 |
|
150 /* |
|
151 ;;; Local Variables: *** |
|
152 ;;; mode: C++ *** |
|
153 ;;; End: *** |
|
154 */ |