Adaptive
Adaptive integration algorithm using RMS formulae
Interface
#include <codecogs/maths/calculus/quadrature/adaptive.h>
using namespace Maths::Calculus::Quadrature;
static double integrate(double (*f)(double), double a, double b)static void dqxrul(double (*f)(double), double xl, double xu, double &y, double &ya, double &ym, int &ke, int &k1, double *fv1, double *fv2, int &l1, int &l2)static void dqxlqm(double (*f)(double), double a, double b, double &result, double &abserr, double &resabs, double &resasc, double *vr, double *vs, int &lr, int &ls)static void dqxrrd(double (*f)(double), double *z, int lz, double &xl, double &xu, double *r, double *s, int &lr, int &ls)static void dqpsrt(int last, int &maxerr, double &ermax, double *elist, int *iord, int nrmax)static void dqelg(int &n, double *epstab, double &result, double &abserr, double *res3la, int &nres)static void dqxgse(double (*f)(double), double a, double b, double &result, double &abserr, int &ier, double *alist, double *blist, double *rlist, double *elist, int *iord, int &last, double *valp, double *valn, int *lp, int *ln)
Overview
The aim of this module is to implement an algorithm that can automatically estimate the definite integral of any one-variable function over some prescribed closed interval :
The algorithm should give proper estimates for the definite integral even if the function to integrate is singular at unknown positions in the integration interval .
This module implements an adaptive integration algorithm using RMS formulae, which is an improved version of the algorithm used in the quadpack Netlib library. The algorithm is able to automatically handle bad behavior in the integrand, like singularities at unknown positions in the integration interval.
Click for more details on RMS formulae
This module is based on the quadpack Netlib library, but replaces its local quadrature module (LQM) from using a pair of Gauss-Kronrod formulae called QK21 , to using four RMS formulae with 13, 19, 27 and 41 nodes called ,
,
and
correspondingly. These are the best formulae found by the original authors, among the total of 27 families of RMS formulae.
The algorithm is numbered 691 in the ACM mathematical software list and its authors are Paola Favati, Grazia Lotti and Francesco Romani. A link to their paper is provided in the reference list below.
The main function in this module is integrate, which takes as parameters the integrand and the limits of the integration interval, and returns the estimated value of the integral.
The following example uses the integrate function to estimate the integral of
over the unit interval [0, 1]. Note that this integrand is singular at both end points of the unit interval.
#include <codecogs/maths/calculus/quadrature/adaptive.h>
#include <iostream>
#include <iomanip>
// define the integrand
double f(double x)
{
return log(x) * sqrt(x / (1 - x));
}
int main()
{
// calculate the integral
double integral = Maths::Calculus::Quadrature::Adaptive::integrate(f, 0, 1);
// set the display precision to 15 digits
std::cout << std::setprecision(15);
// display the integral value
std::cout << "Integral: " << integral << std::endl;
return 0;
}Output:
Integral: -0.606789763508705
References
- Algorithm 691: Improving QUADPACK automatic integration routines, http://portal.acm.org/citation.cfm?id=108556.108580
- The quadpack library, http://www.netlib.org/quadpack/
- The MathWorld page on Wynn's epsilon method, http://mathworld.wolfram.com/WynnsEpsilonMethod.html
Members of Adaptive
STATIC CLASS METHOD
integrate
This function estimates the definite integral
using an adaptive integration algorithm based on RMS formulae.
Parameters
Returns
STATIC CLASS METHOD
dqxrul
This method computes
with error estimate and conditionally computes
by using a RMS rule.
Parameters
STATIC CLASS METHOD
dqxlqm
This method implements the local quadrature module (LQM) used when estimating the integral. Instead of using the pair QK21 of Gauss-Kronrod rules, this LQM implements four RMS formulae of 13, 19, 27 and 41 nodes called ,
,
and
respectively.
The integrals computed by this method are
with its error estimate and:
Parameters
STATIC CLASS METHOD
dqxrrd
This method reorders the computed functional values before the bisection of an interval.
Parameters
STATIC CLASS METHOD
dqpsrt
This method maintains the descending ordering in the list of the local error estimates resulting from the interval subdivision process. At each call, two error estimates are inserted using the sequential search method, top-down for the largest error estimate and bottom-up for the smallest error estimate.
Parameters
STATIC CLASS METHOD
dqelg
This method determines the limit of a given sequence of approximation, by means of the algorithm of P. Wynn. An estimate of the absolute error is also given.
The condensed table is computed. Only those elements needed for the computation of the next diagonal are preserved.
Parameters
STATIC CLASS METHOD
dqxgse
This method calculates an approximation to the definite integral
hopefully satisfying the following claim for accuracy: