![]() |
Home | Libraries | People | FAQ | More |
The kernel objects provide signature compatible functions for the integration of an integrand. The minimum arguments required are the integrand, the lower and upper limits of integration, and result which is used to return the approximation of the integral.
It is usual to have an estimation of the error in the approximation of the integral. The integration routines accept an error estimator argument, which is used to pass a (stateful) error estimation function object. The error estimator can be passed using the error_estimator method.
As error estimation is such a fundamental requirement for using quadrature, no attempt has been made to optimise the kernels for the case where an error estimator is not provided.
Currently there is only one error estimation scheme implemented, error_estimator in error_estimator.hpp, that implements the scheme used in QUADPACK library. The sample program kernel_error_estimation.cpp illustrates its use.
#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; quadrature::kronrod_gauss<15> integrator; // declare the error estimator quadrature::error_estimator<double,double> error_estimator; // integrate x^2 on [0,1] integrator.error_estimator(error_estimator)(_1*_1, 0., 1., result); std::cout << "integral(x^2) on [0,1] is " << result << " with error estimate " << error_estimator.absolute_error() << std::endl; return EXIT_SUCCESS; }
A recorder is a (possibly stateful) function object that is passed the abscissa and integrand value each time the integrand is evaluated. This can be used to record, or otherwise process, the function values. The recorder can be passed using the recorder method.
There are several recorders implemented. The container_pair_recorder stores the function values as (domain,image) pairs ina container. The stream_recorder writes the function values to an output stream.
The sample program kernel_recorder.cpp illustrates the use of the stream_recorder.
#include <boost/numeric/quadrature/kronrodgauss.hpp> #include <boost/numeric/quadrature/stream_recorder.hpp> #include <boost/lambda/lambda.hpp> #include <iostream> namespace quadrature=boost::numeric::quadrature; using namespace boost::lambda; int main() { double result; quadrature::kronrod_gauss<15> integrator; // declare the recorder quadrature::stream_recorder recorder(std::cout); // integrate x^2 on [0,1] integrator.recorder(recorder)(_1*_1, 0., 1., result); std::cout << "integral(x^2) on [0,1] is " << result << std::endl; return EXIT_SUCCESS; }
Some integration kernels have properties such that data calculated in one evaluation of an integrand can be used in another integration over a sub interval of the integrand. An example of this is the Recursive Monotone Stable (RMS) kernel, that uses binary interval bisection.
To support the reuse of data across invocations of the integration kernel, a kernel data object may be passed to the integrator using the kernel_data method. This is mainly of interest to developers of new integration kernels or new globally adaptive integrators.
The type of kernel data required is obtainable from the detail::kernel_interval
trait.
#include <boost/numeric/quadrature/rms.hpp> #include <boost/lambda/lambda.hpp> #include <iostream> namespace quadrature=boost::numeric::quadrature; using namespace boost::lambda; int main() { double result; quadrature::rms<19,13> integrator; // declare the kernel data quadrature::detail::kernel_interval< quadrature::rms<19,13>, double, double>::type kernel_data; // integrate x^2 on [0,1] integrator.kernel_data(kernel_data)(_1*_1, 0., 1., result); std::cout << "integral(x^2) on [0,1] is " << result << std::endl; return EXIT_SUCCESS; }
| Copyright © 2007 Hugo Duncan |