GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Quad.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_Quad_h)
27 #define octave_Quad_h 1
28 
29 #include "octave-config.h"
30 
31 #include "dColVector.h"
32 #include "fColVector.h"
33 
34 typedef double (*integrand_fcn) (double x);
35 typedef float (*float_integrand_fcn) (float x);
36 
37 #include "Quad-opts.h"
38 
39 class
41 Quad : public Quad_options
42 {
43 public:
44 
45  Quad () = delete;
46 
48  : Quad_options (), m_f (fcn), m_ff () { }
49 
51  : Quad_options (), m_f (), m_ff (fcn) { }
52 
53  OCTAVE_DEFAULT_COPY_MOVE (Quad)
54 
55  virtual ~Quad () = default;
56 
57  virtual double integrate ()
58  {
59  octave_idx_type ier, neval;
60  double abserr;
61  return do_integrate (ier, neval, abserr);
62  }
63 
64  virtual float float_integrate ()
65  {
66  octave_idx_type ier, neval;
67  float abserr;
68  return do_integrate (ier, neval, abserr);
69  }
70 
71  virtual double integrate (octave_idx_type& ier)
72  {
73  octave_idx_type neval;
74  double abserr;
75  return do_integrate (ier, neval, abserr);
76  }
77 
78  virtual float float_integrate (octave_idx_type& ier)
79  {
80  octave_idx_type neval;
81  float abserr;
82  return do_integrate (ier, neval, abserr);
83  }
84 
85  virtual double integrate (octave_idx_type& ier, octave_idx_type& neval)
86  {
87  double abserr;
88  return do_integrate (ier, neval, abserr);
89  }
90 
91  virtual float float_integrate (octave_idx_type& ier, octave_idx_type& neval)
92  {
93  float abserr;
94  return do_integrate (ier, neval, abserr);
95  }
96 
97  virtual double integrate (octave_idx_type& ier, octave_idx_type& neval,
98  double& abserr)
99  {
100  return do_integrate (ier, neval, abserr);
101  }
102 
103  virtual float float_integrate (octave_idx_type& ier, octave_idx_type& neval,
104  float& abserr)
105  {
106  return do_integrate (ier, neval, abserr);
107  }
108 
109  virtual double do_integrate (octave_idx_type& ier, octave_idx_type& neval,
110  double& abserr) = 0;
111 
112  virtual float do_integrate (octave_idx_type& ier, octave_idx_type& neval,
113  float& abserr) = 0;
114 
115 protected:
116 
119 };
120 
121 class
123 DefQuad : public Quad
124 {
125 public:
126 
127  DefQuad () = delete;
128 
130  : Quad (fcn), m_lower_limit (0.0), m_upper_limit (1.0), m_singularities ()
131  { }
132 
133  DefQuad (integrand_fcn fcn, double ll, double ul)
134  : Quad (fcn), m_lower_limit (ll), m_upper_limit (ul), m_singularities ()
135  { }
136 
137  DefQuad (integrand_fcn fcn, double ll, double ul,
138  const ColumnVector& sing)
139  : Quad (fcn), m_lower_limit (ll), m_upper_limit (ul),
140  m_singularities (sing) { }
141 
142  DefQuad (integrand_fcn fcn, const ColumnVector& sing)
143  : Quad (fcn), m_lower_limit (0.0), m_upper_limit (1.0),
144  m_singularities (sing) { }
145 
146  OCTAVE_DEFAULT_COPY_MOVE_DELETE (DefQuad)
147 
148  double do_integrate (octave_idx_type& ier, octave_idx_type& neval,
149  double& abserr);
150 
151  OCTAVE_NORETURN float do_integrate (octave_idx_type& ier,
152  octave_idx_type& neval, float& abserr);
153 
154 private:
155 
156  double m_lower_limit;
157  double m_upper_limit;
158 
159  ColumnVector m_singularities;
160 };
161 
162 class
164 IndefQuad : public Quad
165 {
166 public:
167 
168  enum IntegralType { bound_to_inf, neg_inf_to_bound, doubly_infinite };
169 
170  IndefQuad () = delete;
171 
173  : Quad (fcn), m_bound (0.0), m_type (bound_to_inf) { }
174 
176  : Quad (fcn), m_bound (b), m_type (t) { }
177 
178  OCTAVE_DEFAULT_COPY_MOVE_DELETE (IndefQuad)
179 
180  double do_integrate (octave_idx_type& ier, octave_idx_type& neval,
181  double& abserr);
182 
183  OCTAVE_NORETURN float do_integrate (octave_idx_type& ier,
184  octave_idx_type& neval, float& abserr);
185 
186 private:
187 
188  double m_bound;
189  IntegralType m_type;
190 };
191 
192 class
194 FloatDefQuad : public Quad
195 {
196 public:
197 
198  FloatDefQuad () = delete;
199 
201  : Quad (fcn), m_lower_limit (0.0), m_upper_limit (1.0), m_singularities ()
202  { }
203 
204  FloatDefQuad (float_integrand_fcn fcn, float ll, float ul)
205  : Quad (fcn), m_lower_limit (ll), m_upper_limit (ul), m_singularities ()
206  { }
207 
208  FloatDefQuad (float_integrand_fcn fcn, float ll, float ul,
209  const FloatColumnVector& sing)
210  : Quad (fcn), m_lower_limit (ll), m_upper_limit (ul),
211  m_singularities (sing) { }
212 
214  : Quad (fcn), m_lower_limit (0.0), m_upper_limit (1.0),
215  m_singularities (sing) { }
216 
217  OCTAVE_DEFAULT_COPY_MOVE_DELETE (FloatDefQuad)
218 
219  OCTAVE_NORETURN double do_integrate (octave_idx_type& ier,
220  octave_idx_type& neval, double& abserr);
221 
222  float do_integrate (octave_idx_type& ier, octave_idx_type& neval,
223  float& abserr);
224 
225 private:
226 
227  float m_lower_limit;
228  float m_upper_limit;
229 
230  FloatColumnVector m_singularities;
231 };
232 
233 class
235 FloatIndefQuad : public Quad
236 {
237 public:
238 
239  enum IntegralType { bound_to_inf, neg_inf_to_bound, doubly_infinite };
240 
241  FloatIndefQuad () = delete;
242 
244  : Quad (fcn), m_bound (0.0), m_type (bound_to_inf) { }
245 
247  : Quad (fcn), m_bound (b), m_type (t) { }
248 
249  OCTAVE_DEFAULT_COPY_MOVE_DELETE (FloatIndefQuad)
250 
251  OCTAVE_NORETURN double do_integrate (octave_idx_type& ier,
252  octave_idx_type& neval, double& abserr);
253 
254  float do_integrate (octave_idx_type& ier, octave_idx_type& neval,
255  float& abserr);
256 
257 private:
258 
259  float m_bound;
260  IntegralType m_type;
261 };
262 
263 #endif
double(* integrand_fcn)(double x)
Definition: Quad.h:34
float(* float_integrand_fcn)(float x)
Definition: Quad.h:35
Definition: Quad.h:124
DefQuad(integrand_fcn fcn)
Definition: Quad.h:129
DefQuad(integrand_fcn fcn, const ColumnVector &sing)
Definition: Quad.h:142
DefQuad()=delete
DefQuad(integrand_fcn fcn, double ll, double ul, const ColumnVector &sing)
Definition: Quad.h:137
DefQuad(integrand_fcn fcn, double ll, double ul)
Definition: Quad.h:133
FloatDefQuad(float_integrand_fcn fcn)
Definition: Quad.h:200
FloatDefQuad()=delete
FloatDefQuad(float_integrand_fcn fcn, const FloatColumnVector &sing)
Definition: Quad.h:213
FloatDefQuad(float_integrand_fcn fcn, float ll, float ul, const FloatColumnVector &sing)
Definition: Quad.h:208
FloatDefQuad(float_integrand_fcn fcn, float ll, float ul)
Definition: Quad.h:204
FloatIndefQuad(float_integrand_fcn fcn, double b, IntegralType t)
Definition: Quad.h:246
@ bound_to_inf
Definition: Quad.h:239
FloatIndefQuad(float_integrand_fcn fcn)
Definition: Quad.h:243
FloatIndefQuad()=delete
IndefQuad()=delete
IndefQuad(integrand_fcn fcn, double b, IntegralType t)
Definition: Quad.h:175
IndefQuad(integrand_fcn fcn)
Definition: Quad.h:172
IntegralType
Definition: Quad.h:168
@ bound_to_inf
Definition: Quad.h:168
Definition: Quad.h:42
virtual double integrate(octave_idx_type &ier, octave_idx_type &neval)
Definition: Quad.h:85
virtual float do_integrate(octave_idx_type &ier, octave_idx_type &neval, float &abserr)=0
float_integrand_fcn m_ff
Definition: Quad.h:118
virtual double integrate(octave_idx_type &ier, octave_idx_type &neval, double &abserr)
Definition: Quad.h:97
virtual double do_integrate(octave_idx_type &ier, octave_idx_type &neval, double &abserr)=0
Quad(float_integrand_fcn fcn)
Definition: Quad.h:50
virtual double integrate(octave_idx_type &ier)
Definition: Quad.h:71
Quad()=delete
integrand_fcn m_f
Definition: Quad.h:117
virtual float float_integrate()
Definition: Quad.h:64
virtual float float_integrate(octave_idx_type &ier)
Definition: Quad.h:78
virtual float float_integrate(octave_idx_type &ier, octave_idx_type &neval)
Definition: Quad.h:91
Quad(integrand_fcn fcn)
Definition: Quad.h:47
virtual float float_integrate(octave_idx_type &ier, octave_idx_type &neval, float &abserr)
Definition: Quad.h:103
F77_RET_T const F77_DBLE * x
#define OCTAVE_API
Definition: main.cc:55