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