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

◆ integrate_1d() [2/2]

template<typename F >
double stan::math::integrate_1d ( const F &  f,
double  a,
double  b,
const std::vector< double > &  theta,
const std::vector< double > &  x_r,
const std::vector< int > &  x_i,
std::ostream *  msgs,
const double  relative_tolerance = std::sqrt(EPSILON) 
)
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.

Template Parameters
TType of f
Parameters
fthe function to be integrated
alower limit of integration
bupper limit of integration
thetaadditional parameters to be passed to f
x_radditional data to be passed to f
x_iadditional integer data to be passed to f
[in,out]msgsthe print stream for warning messages
relative_tolerancetolerance passed to Boost quadrature
Returns
numeric integral of function f

Definition at line 239 of file integrate_1d.hpp.