Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-00ddc7f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Integrate.h
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien Creighton, Drew Keppel
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20#ifndef _INTEGRATE_H
21#define _INTEGRATE_H
22
23#include <lal/LALDatatypes.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29
30/**
31 * \defgroup Integrate_h Header Integrate.h
32 * \ingroup lal_utilities
33 *
34 * \brief Integrates a function.
35 *
36 * ### Synopsis ###
37 *
38 * \code
39 * #include <lal/Integrate.h>
40 * \endcode
41 *
42 * This header covers the routines for integrating a function.
43 *
44 * ### Description ###
45 *
46 * The routine \c LALSRombergIntegrate() performs the integral specified by the
47 * structure \c input and the result is returned as \c result. Any
48 * additional parameters (other than the integration variable \f$x\f$) can be passed
49 * as \c params. The routine \c LALSRombergIntegrate() does not use
50 * \c params but just passes it to the integrand. The routine
51 * \c LALDRombergIntegrate() is the same but for double precision.
52 *
53 * ### Operating Instructions ###
54 *
55 * The following program performs the integral \f$\int_0^2F(x)dx\f$ where
56 * \f$F(x)=x^4\log(x+\sqrt{x^2+1})\f$.
57 *
58 * \code
59 * #include <math.h>
60 * #include <lal/LALStdlib.h>
61 * #include <lal/Integrate.h>
62 *
63 * static void F( LALStatus *s, REAL4 *y, REAL4 x, void *p )
64 * {
65 * REAL4 x2 = x*x;
66 * REAL4 x4 = x2*x2;
67 * INITSTATUS(s);
68 * ASSERT( !p, s, 1, "Non-null pointer" );
69 * y = x4 * log( x + sqrt( x2 + 1 ) );
70 * RETURN( s );
71 * }
72 *
73 * int main ()
74 * {
75 * const REAL4 epsilon = 1e-6;
76 * const long double expect = 8.153364119811650205L;
77 * static LALStatus status;
78 * SIntegrateIn intinp;
79 * REAL4 result;
80 *
81 * intinp.function = F;
82 * intinp.xmin = 0;
83 * intinp.xmax = 2;
84 * intinp.type = ClosedInterval;
85 *
86 * LALSRombergIntegrate( &status, &result, &intinp, NULL );
87 * if ( fabs( result - expect ) > epsilon * fabs( expect ) )
88 * {
89 * // integration did not achieve desired accuracy --- exit failure
90 * return 1;
91 * }
92 *
93 * return 0;
94 * }
95 * \endcode
96 *
97 * ### Algorithm ###
98 *
99 * This is an implementation of the Romberg integrating function \c qromb in
100 * Numerical Recipes \cite ptvf1992 .
101 *
102 */
103/** @{ */
104
105/**
106 * Type of integral.
107 * The types of integration are the following:
108 *
109 * I. #ClosedInterval
110 * indicates that the integral should be computed on equal-spaced domain
111 * intervals including the boundary.
112 *
113 * II. #OpenInterval indicates that
114 * the integral should be computed on intervals of the domain not including the
115 * boundary.
116 *
117 * III. #SingularLowerLimit indicates that the integral
118 * should be evaluated on an open interval with a transformation so that a
119 * inverse-square-root singularity at the lower limit can be integrated.
120 *
121 * IV. #SingularUpperLimit is the same as above but for a singularity at the
122 * upper limit.
123 *
124 * V. #InfiniteDomainPow indicates that the integral
125 * should be evaluated over an semi-infinite domain---appropriate when both
126 * limits have the same sign (though one is very large) and when the integrand
127 * vanishes faster than \f$x^{-1}\f$ at infinity.
128 *
129 * VI. #InfiniteDomainExp
130 * indicates that the integral should be evaluated over an infinite domain
131 * starting at \c xmin and going to infinity (\c xmax is ignored)---the
132 * integrand should vanish exponentially for large \f$x\f$.
133 */
134typedef enum
135tagIntegralType
136{
137 ClosedInterval, /**< evaluate integral on a closed interval */
138 OpenInterval, /**< evaluate integral on an open interval */
139 SingularLowerLimit, /**< integrate an inv sqrt singularity at lower limit */
140 SingularUpperLimit, /**< integrate an inv sqrt singularity at upper limit */
141 InfiniteDomainPow, /**< integrate infinite domain with power-law falloff */
142 InfiniteDomainExp /**< integrate infinite domain with exponential falloff */
145
146/* ----- Integrate.c ----- */
147/** \see See \ref Integrate_h for documentation */
148REAL8
150 REAL8 (*f)(REAL8 x, void *params),
151 void *params,
152 REAL8 xmin,
153 REAL8 xmax,
154 IntegralType type
155 );
156
157/** @} */
158
159#ifdef __cplusplus
160}
161#endif
162
163#endif /* _INTEGRATE_H */
static double f(double theta, double y, double xi)
Definition: XLALMarcumQ.c:258
IntegralType
Type of integral.
Definition: Integrate.h:136
REAL8 XLALREAL8RombergIntegrate(REAL8(*f)(REAL8 x, void *params), void *params, REAL8 xmin, REAL8 xmax, IntegralType type)
Definition: Integrate.c:233
@ InfiniteDomainExp
integrate infinite domain with exponential falloff
Definition: Integrate.h:142
@ ClosedInterval
evaluate integral on a closed interval
Definition: Integrate.h:137
@ SingularLowerLimit
integrate an inv sqrt singularity at lower limit
Definition: Integrate.h:139
@ SingularUpperLimit
integrate an inv sqrt singularity at upper limit
Definition: Integrate.h:140
@ InfiniteDomainPow
integrate infinite domain with power-law falloff
Definition: Integrate.h:141
@ OpenInterval
evaluate integral on an open interval
Definition: Integrate.h:138
double REAL8
Double precision real floating-point number (8 bytes).