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

#include <integration.h>

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

Public Member Functions

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

Detailed Description

Fast integration routine.

Interpolations are made with lines.

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);
Trapeze Trap(cosine, cosine.x, inte_low, inte_high);
integralt = Trap();

Definition at line 96 of file integration.h.

Constructor & Destructor Documentation

◆ Trapeze()

Trapeze::Trapeze ( doubleFunction f,
double &  Var,
double  min,
double  max,
double  precision = 1.0e-7,
int  max_iter = 20 
)
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 135 of file integration.h.

136  : func(f), x(Var)
137  {
138  a = min;
139  b = max;
140  EPS = precision;
141  JMAX = max_iter;
142  }
void min(Image< double > &op1, const Image< double > &op2)
void max(Image< double > &op1, const Image< double > &op2)

Member Function Documentation

◆ operator()() [1/2]

double Trapeze::operator() ( )
virtual

Implements doubleFunction.

Definition at line 70 of file integration.cpp.

71 { //adapted from qtrap
72  double s_internal;
73  double olds;
74  int j;
75  olds = -1.0e30;
76  for (j = 1;j <= JMAX;j++)
77  {
78  s_internal = Trap(j); //changed; Trap is integrating fcn
79  if (fabs(s_internal - olds) <= EPS*fabs(olds))
80  return s_internal;
81  if (s_internal == 0.0 && olds == 0.0 && j > 6)
82  return s_internal;
83  olds = s_internal;
84  }
85  REPORT_ERROR(ERR_NUMERICAL,"Too many steps in routine qtrap_y\n");
86 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Error related to numerical calculation.
Definition: xmipp_error.h:179
#define j
double Trap(int n)
Definition: integration.cpp:89

◆ operator()() [2/2]

double Trapeze::operator() ( double  min,
double  max,
double  precision = 1.0e-7,
int  max_iter = 20 
)
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 116 of file integration.h.

118  {
119  a = min;
120  b = max;
121  EPS = precision;
122  JMAX = max_iter;
123  return (*this)();
124  }
void min(Image< double > &op1, const Image< double > &op2)
void max(Image< double > &op1, const Image< double > &op2)

◆ Trap()

double Trapeze::Trap ( int  n)

Workhorse that doublely does the integral.

Definition at line 89 of file integration.cpp.

90 { //adapted from trapzd
91  double tnm;
92  double sum;
93  double del;
94  int j;
95  int it;
96  if (n == 1)
97  {
98  it = 1;
99  x = a;
100  s = func(); //changed
101  x = b;
102  s += func(); //changed
103  return (s *= 0.5 * (b - a));
104  }
105  else
106  {
107  for (it = 1, j = 1;j < n - 1;j++)
108  it <<= 1;
109  tnm = it;
110  del = (b - a) / tnm;
111  x = a + 0.5 * del;
112  for (sum = 0.0, j = 1;j <= it;j++, x += del)
113  sum += func(); //changed
114  s = 0.5 * (s + (b - a) * sum / tnm);
115  return s;
116  }
117 }
float del
#define j
int * n

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