Xmipp  v3.23.11-Nereus
Public Member Functions | List of all members

#include <integration.h>

Inheritance diagram for Romberg:
Inheritance graph
[legend]
Collaboration diagram for Romberg:
Collaboration graph
[legend]

Public Member Functions

virtual double operator() ()
 
double operator() (double min, double max, double precision=1.0e-7)
 
 Romberg (doubleFunction &f, double &Var, double min, double max, double precision=1.0e-7)
 
double midpnt (int n)
 
- Public Member Functions inherited from doubleFunction
virtual ~doubleFunction ()
 

Detailed Description

More accurate integration.

More accurate integration than Trapeze with smaller truncation error (interpolation is made with polynomials)

Example of use:

1) Define function to NumericalIntegration as class:

// Actual function to be NumericalIntegration
class Func1: public doubleFunction
{
// This should be in testinteg
public:
double x;
double cte1, cte2;
// Overloads pure virtual
virtual double operator()()
{
return sqrt(1 + cte1 * cte1 * sin(cte2 * x) * sin(cte2 * x));
}
};

2) In the main code

Func1 cosine; // cosine surface
cosine.cte1 = fabs(cteA * cteA * cteB * cteB * vx * vx);
cosine.cte2 = fabs(cteB * vx);
Romberg Rom(cosine, cosine.x, inte_low, inte_high);
integralt = Rom();

Definition at line 189 of file integration.h.

Constructor & Destructor Documentation

◆ Romberg()

Romberg::Romberg ( doubleFunction f,
double &  Var,
double  min,
double  max,
double  precision = 1.0e-7 
)
inline

Constructor.

Parameter: f Pointer to function to be integrated Parameter: var Integration variable Parameter: min Integration lower limit Parameter: max Integration upper limit Parameter: precision Maximum error allowed Parameter: max_iter Maximum number of iterations

Definition at line 226 of file integration.h.

227  : func(f), x(Var)
228  {
229  s = 0.0;
230  a = min;
231  b = max;
232  EPS = precision;
233  }
void min(Image< double > &op1, const Image< double > &op2)
void max(Image< double > &op1, const Image< double > &op2)

Member Function Documentation

◆ midpnt()

double Romberg::midpnt ( int  n)

Workhorse that doublely does the integral

Definition at line 151 of file integration.cpp.

152 { //adapted from midpoint
153  double tnm;
154  double sum;
155  double del;
156  double ddel;
157  int it;
158  int j;
159  if (n == 1)
160  {
161  x = 0.5 * (a + b); //changed; set x
162  return (s = (b - a) * func()); //changed; evaluate func
163  }
164  else
165  {
166  for (it = 1, j = 1;j < n - 1;j++)
167  it *= 3;
168  tnm = it;
169  del = (b - a) / (3.0 * tnm);
170  ddel = del + del;
171  x = a + 0.5 * del;
172  sum = 0.0;
173  for (j = 1;j <= it;j++)
174  {
175  sum += func(); //changed; evaluate func
176  x += ddel; //changed; set x
177  sum += func(); //changed; evaluate func
178  x += del; //changed; set x
179  }
180  s = (s + (b - a) * sum / tnm) / 3.0;
181  return s;
182  }
183 }
float del
#define j
int * n

◆ operator()() [1/2]

double Romberg::operator() ( )
virtual

Implements doubleFunction.

Definition at line 125 of file integration.cpp.

126 { //adapted from qromb
127  int j;
128  double ss;
129  double dss;
130  std::array<double, JMAXP+2> h;
131  std::array<double, JMAXP+2> s_internal;
132  h[1] = 1.0;
133  for (j = 1;j <= JMAXP;j++)
134  {
135  s_internal[j] = midpnt(j); //changed; midpnt is integrating
136  if (j >= K)
137  { //function
138  polint(&h[j-K], &s_internal[j-K], K, 0.0, ss, dss);
139  if (fabs(dss) <= EPS*fabs(ss))
140  return ss;
141  }
142  s_internal[j+1] = s_internal[j];
143  h[j+1] = h[j] / 9.0;
144  }
145  REPORT_ERROR(ERR_NUMERICAL,"Too many steps in routine Romberg");
146 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
constexpr int JMAXP
Error related to numerical calculation.
Definition: xmipp_error.h:179
void polint(double *xa, double *ya, int n, double x, double &y, double &dy)
#define j
constexpr int K
double midpnt(int n)

◆ operator()() [2/2]

double Romberg::operator() ( double  min,
double  max,
double  precision = 1.0e-7 
)
inline

With parameters.

Parameter: min Integration lower limit Parameter: max Integration upper limit Parameter: precision Maximum error allowed Parameter: max_iter Maximum number of iterations

Definition at line 209 of file integration.h.

210  {
211  a = min;
212  b = max;
213  EPS = precision;
214  return (*this)();
215  }
void min(Image< double > &op1, const Image< double > &op2)
void max(Image< double > &op1, const Image< double > &op2)

The documentation for this class was generated from the following files: