Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ integrate()

template<typename F >
double stan::math::integrate ( const F &  f,
double  a,
double  b,
double  relative_tolerance 
)
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

Template Parameters
TType of f
Parameters
fthe function to be integrated
alower limit of integration
bupper limit of integration
relative_tolerancetarget relative tolerance passed to Boost quadrature
Returns
numeric integral of function f

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.