Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
ROOT::Math::GaussLegendreIntegrator Class Reference

User class for performing function integration.

It will use the Gauss-Legendre Method for function integration in a given interval. This class is implemented from TF1::Integral().

Definition at line 37 of file GaussLegendreIntegrator.h.

Public Member Functions

 GaussLegendreIntegrator (int num=10, double eps=1e-12)
 Basic constructor of GaussLegendreIntegrator.
 ~GaussLegendreIntegrator () override
 Default Destructor.
void AbsValue (bool flag)
 Static function: set the fgAbsValue flag.
double Error () const override
 Return the estimate of the absolute Error of the last Integral calculation.
int GetNumberPoints () const
void GetWeightVectors (double *x, double *w) const
 Returns the arrays x and w containing the abscissa and weight of the Gauss-Legendre n-point quadrature formula.
double Integral () override
 Returns Integral of function on an infinite interval.
double Integral (const std::vector< double > &pts) override
 This method is not implemented.
double Integral (double a, double b) override
 Returns Integral of function between a and b.
double IntegralCauchy (double a, double b, double c) override
 This method is not implemented.
double IntegralLow (double b) override
 Returns Integral of function on a lower semi-infinite interval.
double IntegralUp (double a) override
 Returns Integral of function on an upper semi-infinite interval.
int NEval () const override
 return number of function evaluations in calculating the integral This is equivalent to the number of points
ROOT::Math::IntegratorOneDimOptions Options () const override
 get the option used for the integration
double Result () const override
 Returns the result of the last Integral calculation.
void SetAbsTolerance (double) override
 This method is not implemented.
void SetFunction (const IGenFunction &) override
 Set integration function (flag control if function must be copied inside).
void SetNumberPoints (int num)
 Set the number of points used in the calculation of the integral.
void SetOptions (const ROOT::Math::IntegratorOneDimOptions &opt) override
 set the options (should be re-implemented by derived classes -if more options than tolerance exist
void SetRelTolerance (double) override
 Set the desired relative Error.
int Status () const override
 return the status of the last integration - 0 in case of success
virtual ROOT::Math::IntegrationOneDim::Type Type () const
 return type of integrator

Protected Attributes

double fEpsAbs
 Absolute error.
double fEpsRel
 Relative error.
const IGenFunctionfFunction
 Pointer to function used.
double fLastError
 Error from the last estimation.
double fLastResult
 Result from the last estimation.
int fNum
 Number of points used in the estimation of the integral.
bool fUsedOnce
 Bool value to check if the function was at least called once.
doublefW
 Weights of the points used.
doublefX
 Abscisa of the points used.

Static Protected Attributes

static bool fgAbsValue = false
 AbsValue used for the calculation of the integral.

Private Member Functions

void CalcGaussLegendreSamplingPoints ()
 Type: unsafe but fast interface filling the arrays x and w (static method).
double DoIntegral (double a, double b, const IGenFunction *func) override
 Integration surrogate method.

#include <Math/GaussLegendreIntegrator.h>

Inheritance diagram for ROOT::Math::GaussLegendreIntegrator:
ROOT::Math::GaussIntegrator ROOT::Math::VirtualIntegratorOneDim ROOT::Math::VirtualIntegrator

Constructor & Destructor Documentation

◆ GaussLegendreIntegrator()

ROOT::Math::GaussLegendreIntegrator::GaussLegendreIntegrator ( int num = 10,
double eps = 1e-12 )

Basic constructor of GaussLegendreIntegrator.

@param num Number of desired points to calculate the integration. @param eps Desired relative error.

Definition at line 23 of file GaussLegendreIntegrator.cxx.

◆ ~GaussLegendreIntegrator()

ROOT::Math::GaussLegendreIntegrator::~GaussLegendreIntegrator ( )
override

Default Destructor.

Definition at line 34 of file GaussLegendreIntegrator.cxx.

Member Function Documentation

◆ AbsValue()

void ROOT::Math::GaussIntegrator::AbsValue ( bool flag)
inherited

Static function: set the fgAbsValue flag.

By default TF1::Integral uses the original function value to compute the integral However, TF1::Moment, CentralMoment require to compute the integral using the absolute value of the function.

Definition at line 49 of file GaussIntegrator.cxx.

◆ CalcGaussLegendreSamplingPoints()

void ROOT::Math::GaussLegendreIntegrator::CalcGaussLegendreSamplingPoints ( )
private

Type: unsafe but fast interface filling the arrays x and w (static method).

Given the number of sampling points this routine fills the arrays x and w of length num, containing the abscissa and weight of the Gauss-Legendre n-point quadrature formula.

Gauss-Legendre: W(x)=1 -1<x<1 (j+1)P_{j+1} = (2j+1)xP_j-jP_{j-1}

num is the number of sampling points (>0) x and w are arrays of size num eps is the relative precision

If num<=0 or eps<=0 no action is done.

Reference: Numerical Recipes in C, Second Edition

Definition at line 98 of file GaussLegendreIntegrator.cxx.

◆ DoIntegral()

double ROOT::Math::GaussLegendreIntegrator::DoIntegral ( double a,
double b,
const IGenFunction * func )
overrideprivatevirtual

Integration surrogate method.

Return integral of passed function in interval [a,b] Reimplement method of GaussIntegrator using CalcGaussLegendreSamplingPoints

Reimplemented from ROOT::Math::GaussIntegrator.

Definition at line 60 of file GaussLegendreIntegrator.cxx.

◆ Error()

double ROOT::Math::GaussIntegrator::Error ( ) const
overridevirtualinherited

Return the estimate of the absolute Error of the last Integral calculation.

Implements ROOT::Math::VirtualIntegrator.

Definition at line 176 of file GaussIntegrator.cxx.

◆ GetNumberPoints()

int ROOT::Math::GaussLegendreIntegrator::GetNumberPoints ( ) const
inline

Definition at line 68 of file GaussLegendreIntegrator.h.

◆ GetWeightVectors()

void ROOT::Math::GaussLegendreIntegrator::GetWeightVectors ( double * x,
double * w ) const

Returns the arrays x and w containing the abscissa and weight of the Gauss-Legendre n-point quadrature formula.

Gauss-Legendre: W(x)=1 -1<x<1 (j+1)P_{j+1} = (2j+1)xP_j-jP_{j-1}

Definition at line 51 of file GaussLegendreIntegrator.cxx.

◆ Integral() [1/3]

double ROOT::Math::GaussIntegrator::Integral ( )
overridevirtualinherited

Returns Integral of function on an infinite interval.

This function computes, to an attempted specified accuracy, the value of the integral:

\[ I = \int^{\infty}_{-\infty} f(x)dx \]

Usage: In any arithmetic expression, this function has the approximate value of the integral I.

The integral is mapped onto [0,1] using a transformation then integral computation is surrogated to DoIntegral.

Implements ROOT::Math::VirtualIntegratorOneDim.

Definition at line 56 of file GaussIntegrator.cxx.

◆ Integral() [2/3]

double ROOT::Math::GaussIntegrator::Integral ( const std::vector< double > & pts)
overridevirtualinherited

This method is not implemented.

Implements ROOT::Math::VirtualIntegratorOneDim.

Definition at line 190 of file GaussIntegrator.cxx.

◆ Integral() [3/3]

double ROOT::Math::GaussIntegrator::Integral ( double a,
double b )
overridevirtualinherited

Returns Integral of function between a and b.

Based on original CERNLIB routine DGAUSS by Sigfried Kolbig converted to C++ by Rene Brun

This function computes, to an attempted specified accuracy, the value of the integral.

Method: For any interval [a,b] we define g8(a,b) and g16(a,b) to be the 8-point and 16-point Gaussian quadrature approximations to

\[ I = \int^{b}_{a} f(x)dx \]

and define

\[ r(a,b) = \frac{\left|g_{16}(a,b)-g_{8}(a,b)\right|}{1+\left|g_{16}(a,b)\right|} \]

Then,

\[ G = \sum_{i=1}^{k}g_{16}(x_{i-1},x_{i}) \]

where, starting with \(x_{0} = A\) and finishing with \(x_{k} = B\), the subdivision points \(x_{i}(i=1,2,...)\) are given by

\[ x_{i} = x_{i-1} + \lambda(B-x_{i-1}) \]

\(\lambda\) is equal to the first member of the sequence 1,1/2,1/4,... for which \(r(x_{i-1}, x_{i}) < EPS\). If, at any stage in the process of subdivision, the ratio

\[ q = \left|\frac{x_{i}-x_{i-1}}{B-A}\right| \]

is so small that 1+0.005q is indistinguishable from 1 to machine accuracy, an error exit occurs with the function value set equal to zero.

Accuracy: The user provides absolute and relative error bounds (epsrel and epsabs) and the algorithm will stop when the estimated error is less than the epsabs OR is less than |I| * epsrel. Unless there is severe cancellation of positive and negative values of f(x) over the interval [A,B], the relative error may be considered as specifying a bound on the relative error of I in the case |I|>1, and a bound on the absolute error in the case |I|<1. More precisely, if k is the number of sub-intervals contributing to the approximation (see Method), and if

\[ I_{abs} = \int^{B}_{A} \left|f(x)\right|dx \]

then the relation

\[ \frac{\left|G-I\right|}{I_{abs}+k} < EPS \]

will nearly always be true, provided the routine terminates without printing an error message. For functions f having no singularities in the closed interval [A,B] the accuracy will usually be much higher than this.

Error handling: The requested accuracy cannot be obtained (see Method). The function value is set equal to zero.

Note 1: Values of the function f(x) at the interval end-points A and B are not required. The subprogram may therefore be used when these values are undefined

Implements ROOT::Math::VirtualIntegratorOneDim.

Definition at line 52 of file GaussIntegrator.cxx.

◆ IntegralCauchy()

double ROOT::Math::GaussIntegrator::IntegralCauchy ( double a,
double b,
double c )
overridevirtualinherited

This method is not implemented.

Implements ROOT::Math::VirtualIntegratorOneDim.

Definition at line 197 of file GaussIntegrator.cxx.

◆ IntegralLow()

double ROOT::Math::GaussIntegrator::IntegralLow ( double b)
overridevirtualinherited

Returns Integral of function on a lower semi-infinite interval.

This function computes, to an attempted specified accuracy, the value of the integral:

\[ I = \int^{B}_{-\infty} f(x)dx \]

Usage: In any arithmetic expression, this function has the approximate value of the integral I.

  • B: upper end-point of integration interval.

The integral is mapped onto [0,1] using a transformation then integral computation is surrogated to DoIntegral.

Implements ROOT::Math::VirtualIntegratorOneDim.

Definition at line 66 of file GaussIntegrator.cxx.

◆ IntegralUp()

double ROOT::Math::GaussIntegrator::IntegralUp ( double a)
overridevirtualinherited

Returns Integral of function on an upper semi-infinite interval.

This function computes, to an attempted specified accuracy, the value of the integral:

\[ I = \int^{\infty}_{A} f(x)dx \]

Usage: In any arithmetic expression, this function has the approximate value of the integral I.

  • A: lower end-point of integration interval.

The integral is mapped onto [0,1] using a transformation then integral computation is surrogated to DoIntegral.

Implements ROOT::Math::VirtualIntegratorOneDim.

Definition at line 61 of file GaussIntegrator.cxx.

◆ NEval()

int ROOT::Math::GaussLegendreIntegrator::NEval ( ) const
inlineoverridevirtual

return number of function evaluations in calculating the integral This is equivalent to the number of points

Reimplemented from ROOT::Math::VirtualIntegrator.

Definition at line 74 of file GaussLegendreIntegrator.h.

◆ Options()

ROOT::Math::IntegratorOneDimOptions ROOT::Math::GaussLegendreIntegrator::Options ( ) const
overridevirtual

get the option used for the integration

Reimplemented from ROOT::Math::GaussIntegrator.

Definition at line 157 of file GaussLegendreIntegrator.cxx.

◆ Result()

double ROOT::Math::GaussIntegrator::Result ( ) const
overridevirtualinherited

Returns the result of the last Integral calculation.

Implements ROOT::Math::VirtualIntegrator.

Definition at line 166 of file GaussIntegrator.cxx.

◆ SetAbsTolerance()

void ROOT::Math::GaussLegendreIntegrator::SetAbsTolerance ( double )
overridevirtual

This method is not implemented.

Reimplemented from ROOT::Math::GaussIntegrator.

Definition at line 93 of file GaussLegendreIntegrator.cxx.

◆ SetFunction()

void ROOT::Math::GaussIntegrator::SetFunction ( const IGenFunction & function)
overridevirtualinherited

Set integration function (flag control if function must be copied inside).

@param f Function to be used in the calculations.

Implements ROOT::Math::VirtualIntegratorOneDim.

Definition at line 182 of file GaussIntegrator.cxx.

◆ SetNumberPoints()

void ROOT::Math::GaussLegendreIntegrator::SetNumberPoints ( int num)

Set the number of points used in the calculation of the integral.

Definition at line 43 of file GaussLegendreIntegrator.cxx.

◆ SetOptions()

void ROOT::Math::GaussLegendreIntegrator::SetOptions ( const ROOT::Math::IntegratorOneDimOptions & opt)
overridevirtual

set the options (should be re-implemented by derived classes -if more options than tolerance exist

Reimplemented from ROOT::Math::GaussIntegrator.

Definition at line 167 of file GaussLegendreIntegrator.cxx.

◆ SetRelTolerance()

void ROOT::Math::GaussLegendreIntegrator::SetRelTolerance ( double eps)
overridevirtual

Set the desired relative Error.

Reimplemented from ROOT::Math::GaussIntegrator.

Definition at line 86 of file GaussLegendreIntegrator.cxx.

◆ Status()

int ROOT::Math::GaussIntegrator::Status ( ) const
overridevirtualinherited

return the status of the last integration - 0 in case of success

Implements ROOT::Math::VirtualIntegrator.

Definition at line 179 of file GaussIntegrator.cxx.

◆ Type()

virtual ROOT::Math::IntegrationOneDim::Type ROOT::Math::VirtualIntegratorOneDim::Type ( ) const
inlinevirtualinherited

return type of integrator

Definition at line 134 of file VirtualIntegrator.h.

Member Data Documentation

◆ fEpsAbs

double ROOT::Math::GaussIntegrator::fEpsAbs
protectedinherited

Absolute error.

Definition at line 223 of file GaussIntegrator.h.

◆ fEpsRel

double ROOT::Math::GaussIntegrator::fEpsRel
protectedinherited

Relative error.

Definition at line 222 of file GaussIntegrator.h.

◆ fFunction

const IGenFunction* ROOT::Math::GaussIntegrator::fFunction
protectedinherited

Pointer to function used.

Definition at line 227 of file GaussIntegrator.h.

◆ fgAbsValue

bool ROOT::Math::GaussIntegrator::fgAbsValue = false
staticprotectedinherited

AbsValue used for the calculation of the integral.

Definition at line 221 of file GaussIntegrator.h.

◆ fLastError

double ROOT::Math::GaussIntegrator::fLastError
protectedinherited

Error from the last estimation.

Definition at line 226 of file GaussIntegrator.h.

◆ fLastResult

double ROOT::Math::GaussIntegrator::fLastResult
protectedinherited

Result from the last estimation.

Definition at line 225 of file GaussIntegrator.h.

◆ fNum

int ROOT::Math::GaussLegendreIntegrator::fNum
protected

Number of points used in the estimation of the integral.

Definition at line 113 of file GaussLegendreIntegrator.h.

◆ fUsedOnce

bool ROOT::Math::GaussIntegrator::fUsedOnce
protectedinherited

Bool value to check if the function was at least called once.

Definition at line 224 of file GaussIntegrator.h.

◆ fW

double* ROOT::Math::GaussLegendreIntegrator::fW
protected

Weights of the points used.

Definition at line 115 of file GaussLegendreIntegrator.h.

◆ fX

double* ROOT::Math::GaussLegendreIntegrator::fX
protected

Abscisa of the points used.

Definition at line 114 of file GaussLegendreIntegrator.h.


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