Stan Math Library
5.0.0
Automatic Differentiation
|
|
inline |
Integrate a single variable function f from a to b to within a specified relative tolerance.
This function assumes a is less than b.
The signature for f should be: double f(double x, double xc)
It should return the value of the function evaluated at x.
Depending on whether or not a is finite or negative infinity and b is finite or positive infinity, a different version of the 1d quadrature algorithm from the Boost quadrature library is chosen.
Integrals that cross zero are broken into two, and the separate integrals are each integrated to the given relative tolerance.
For integrals with finite limits, the xc argument is the distance to the nearest boundary. So for a > 0, b > 0, it will be a - x for x closer to a, and b - x for x closer to b. xc is computed in a way that avoids the precision loss of computing a - x or b - x manually. For integrals that cross zero, xc can take values a - x, -x, or b - x depending on which integration limit it is nearest.
If either limit is infinite, xc is set to NaN
T | Type of f |
f | the function to be integrated |
a | lower limit of integration |
b | upper limit of integration |
relative_tolerance | target relative tolerance passed to Boost quadrature |
If the integral crosses zero, break it into two (advice from the Boost implementation: https://www.boost.org/doc/libs/1_66_0/libs/math/doc/html/math_toolkit/double_exponential/de_caveats.html)
Definition at line 52 of file integrate_1d.hpp.