![]() |
Home | Libraries | People | FAQ | More |
All the code in the library is in the namespace boost::numeric::quadrature,
and all headers are in the boost/numeric/quadrature
directory.
Quadrature is the numerical computation of a definite integral. The library contains kernels, that implement quadrature over a fixed number of points (depending on the kernel), and algorithms that use the kernels to provide globally adaptive integrators.
The library contains two classes of integration kernels, Kronrod-Gauss and Recursive Monotone Stable. The kernels are templated on integers describing there size.
Each kernel is an object, which is instantiated and can be used to integrate as many integrands as desired.
To use the kernel, the integrand has to be provided as a function object. This simple example uses a 15 point Kronrod-Gauss kernel to integrate x^2 with a function object defined using Boost.Lambda.
#include <boost/numeric/quadrature/kronrodgauss.hpp> #include <boost/numeric/quadrature/error_estimator.hpp> #include <boost/lambda/lambda.hpp> #include <iostream> namespace quadrature=boost::numeric::quadrature; using namespace boost::lambda; int main() { double result; // declare the kernel quadrature::kronrod_gauss<15> integrator; // integrate x^2 on [0,1] integrator(_1*_1, 0., 1., result); // display the result std::cout << "integral(x^2) on [0,1] is " << result << std::endl; return EXIT_SUCCESS; }
Not all integrands lend themselves to simple integration using a fixed number of points. Globally adaptive schemes are designed to be more robust to integrand behaviour. The apply an integration kernel over sub-intervals of the range of integration, such that difficult areas are isolated and receive extra attention.
#include <boost/numeric/quadrature/adaptive.hpp> #include <boost/numeric/quadrature/kronrodgauss.hpp> #include <iostream> #include <cmath> namespace quadrature=boost::numeric::quadrature; struct f { double operator()(double x) const { return x/std::log(x); } }; int main() { double answer, error_estimate; // integrate x/log(x) on [0,1] quadrature::adaptive()(f(), 0., 1., answer, error_estimate); std::cout << "integtral(x/log(x)) on [0,1] is " << answer << " with error estimate " << error_estimate << std::endl; return EXIT_SUCCESS; }
Some of the features that are not available in many numeric codes, and have hopefully been implemented with zero runtime cost:
* ability to record function evaluation values * pluggable error estimation * pluggable collection of algorithm performance information
| Copyright © 2007 Hugo Duncan |