Stan Math Library
5.0.0
Automatic Differentiation
|
|
inline |
Compute the integral of the single variable function f from a to b to within a specified relative tolerance.
a and b can be finite or infinite.
The signature for f should be: double f(double x, double xc, const std::vector<double>& theta, const std::vector<double>& x_r, const std::vector<int>& x_i, std::ostream* msgs)
It should return the value of the function evaluated at x. Any errors should be printed to the msgs stream.
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
The integration algorithm terminates when
\[ \frac{{|I_{n + 1} - I_n|}}{{|I|_{n + 1}}} < \text{relative tolerance} \]
where \(I_{n}\) is the nth estimate of the integral and \(|I|_{n}\) is the nth estimate of the norm of the integral.
Integrals that cross zero are split into two. In this case, each integral is separately integrated to the given relative_tolerance.
T | Type of f |
f | the function to be integrated | |
a | lower limit of integration | |
b | upper limit of integration | |
theta | additional parameters to be passed to f | |
x_r | additional data to be passed to f | |
x_i | additional integer data to be passed to f | |
[in,out] | msgs | the print stream for warning messages |
relative_tolerance | tolerance passed to Boost quadrature |
Definition at line 239 of file integrate_1d.hpp.