Xmipp  v3.23.11-Nereus
integration.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Javier Rodrguez Falces (jrodriguez@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #ifndef CORE_INTEGRATION_H
27 #define CORE_INTEGRATION_H
28 
44 double integrateNewtonCotes(double(*f)(double), double a, double b, int N);
45 
52 {
53 public:
54  virtual double operator()()=0; // pure virtual function
55  virtual ~doubleFunction()
56  {} // virtual destructor
57 };
58 
96 class Trapeze: public doubleFunction
97 {
98  double s;
99  doubleFunction& func; // the generic function to be NumericalIntegration
100  double a; // integral limits
101  double b; // integral limits
102  double& x; // integration variable
103  double EPS; // desired accuracy
104  int JMAX; // 2**(JMAX) = max number of func. evaluation
105 
106 public:
107  // Overloads pure virtual function.
108  virtual double operator()();
109 
116  double operator()(double min, double max,
117  double precision = 1.0e-7, int max_iter = 20)
118  {
119  a = min;
120  b = max;
121  EPS = precision;
122  JMAX = max_iter;
123  return (*this)();
124  }
125 
135  Trapeze(doubleFunction& f, double& Var, double min, double max,
136  double precision = 1.0e-7, int max_iter = 20) : func(f), x(Var)
137  {
138  a = min;
139  b = max;
140  EPS = precision;
141  JMAX = max_iter;
142  }
143 
146  double Trap(int n);
147 };
148 
189 class Romberg : public doubleFunction
190 {
191  double s;
192  doubleFunction& func; // the function to be Numerical_interationd
193  double a; // integral limits
194  double b; // integral limits
195  double& x; // integration variable
196  double EPS; // desired accuracy
197 
198 public:
199  // TODO Document
200  virtual double operator()();
201 
209  double operator()(double min, double max, double precision = 1.0e-7)
210  {
211  a = min;
212  b = max;
213  EPS = precision;
214  return (*this)();
215  }
216 
226  Romberg(doubleFunction& f, double& Var, double min, double max,
227  double precision = 1.0e-7) : func(f), x(Var)
228  {
229  s = 0.0;
230  a = min;
231  b = max;
232  EPS = precision;
233  }
234 
237  double midpnt(int n);
238 };
239 #endif
void min(Image< double > &op1, const Image< double > &op2)
double operator()(double min, double max, double precision=1.0e-7)
Definition: integration.h:209
virtual double operator()()=0
doublereal * x
double integrateNewtonCotes(double(*f)(double), double a, double b, int N)
Definition: integration.cpp:32
doublereal * b
double * f
Romberg(doubleFunction &f, double &Var, double min, double max, double precision=1.0e-7)
Definition: integration.h:226
void max(Image< double > &op1, const Image< double > &op2)
double operator()(double min, double max, double precision=1.0e-7, int max_iter=20)
Definition: integration.h:116
Trapeze(doubleFunction &f, double &Var, double min, double max, double precision=1.0e-7, int max_iter=20)
Definition: integration.h:135
constexpr long double EPS
virtual ~doubleFunction()
Definition: integration.h:55
int * n
doublereal * a