LAL  7.5.0.1-b72065a

Detailed Description

Integrates a function.

Synopsis

#include <lal/Integrate.h>

This header covers the routines for integrating a function.

Description

The routine LALSRombergIntegrate() performs the integral specified by the structure input and the result is returned as result. Any additional parameters (other than the integration variable \(x\)) can be passed as params. The routine LALSRombergIntegrate() does not use params but just passes it to the integrand. The routine LALDRombergIntegrate() is the same but for double precision.

Operating Instructions

The following program performs the integral \(\int_0^2F(x)dx\) where \(F(x)=x^4\log(x+\sqrt{x^2+1})\).

#include <math.h>
#include <lal/LALStdlib.h>
#include <lal/Integrate.h>
static void F( LALStatus *s, REAL4 *y, REAL4 x, void *p )
{
REAL4 x2 = x*x;
REAL4 x4 = x2*x2;
ASSERT( !p, s, 1, "Non-null pointer" );
y = x4 * log( x + sqrt( x2 + 1 ) );
RETURN( s );
}
int main ()
{
const REAL4 epsilon = 1e-6;
const long double expect = 8.153364119811650205L;
SIntegrateIn intinp;
REAL4 result;
intinp.function = F;
intinp.xmin = 0;
intinp.xmax = 2;
intinp.type = ClosedInterval;
LALSRombergIntegrate( &status, &result, &intinp, NULL );
if ( fabs( result - expect ) > epsilon * fabs( expect ) )
{
// integration did not achieve desired accuracy --- exit failure
return 1;
}
return 0;
}
#define ASSERT(assertion, statusptr, code, mesg)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
int main(int argc, char *argv[])
Definition: cache.c:25
@ ClosedInterval
evaluate integral on a closed interval
Definition: Integrate.h:137
float REAL4
Single precision real floating-point number (4 bytes).
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947

Algorithm

This is an implementation of the Romberg integrating function qromb in Numerical Recipes [22] .

Prototypes

REAL8 XLALREAL8RombergIntegrate (REAL8(*f)(REAL8 x, void *params), void *params, REAL8 xmin, REAL8 xmax, IntegralType type)
 

Enumerations

enum  IntegralType {
  ClosedInterval , OpenInterval , SingularLowerLimit , SingularUpperLimit ,
  InfiniteDomainPow , InfiniteDomainExp
}
 Type of integral. More...
 

Files

file  IntegrateTest.c
 Tests the routines in Header Integrate.h by performing a suite of numerical integrations and checking the accuracy of the results.
 

Function Documentation

◆ XLALREAL8RombergIntegrate()

REAL8 XLALREAL8RombergIntegrate ( REAL8(*)(REAL8 x, void *params)  f,
void *  params,
REAL8  xmin,
REAL8  xmax,
IntegralType  type 
)
See also
See Header Integrate.h for documentation

Definition at line 233 of file Integrate.c.

Enumeration Type Documentation

◆ IntegralType

Type of integral.

The types of integration are the following:

I. ClosedInterval indicates that the integral should be computed on equal-spaced domain intervals including the boundary.

II. OpenInterval indicates that the integral should be computed on intervals of the domain not including the boundary.

III. SingularLowerLimit indicates that the integral should be evaluated on an open interval with a transformation so that a inverse-square-root singularity at the lower limit can be integrated.

IV. SingularUpperLimit is the same as above but for a singularity at the upper limit.

V. InfiniteDomainPow indicates that the integral should be evaluated over an semi-infinite domain—appropriate when both limits have the same sign (though one is very large) and when the integrand vanishes faster than \(x^{-1}\) at infinity.

VI. InfiniteDomainExp indicates that the integral should be evaluated over an infinite domain starting at xmin and going to infinity (xmax is ignored)—the integrand should vanish exponentially for large \(x\).

Enumerator
ClosedInterval 

evaluate integral on a closed interval

OpenInterval 

evaluate integral on an open interval

SingularLowerLimit 

integrate an inv sqrt singularity at lower limit

SingularUpperLimit 

integrate an inv sqrt singularity at upper limit

InfiniteDomainPow 

integrate infinite domain with power-law falloff

InfiniteDomainExp 

integrate infinite domain with exponential falloff

Definition at line 134 of file Integrate.h.