As far as I know, there are no functions of the type that you are looking for in the standard library. Here is one of the implementations:
Expanded trapezoidal rule.
For a fixed function f(x) , which must be integrated between the fixed limits a and b , we can double the number of intervals in the extended trapezoidal rule without losing the advantages of the previous work. The roughest implementation of the trapezoidal rule is to average the function at its ends a and b . The first step of refinement is to add to this average the value of the function in the middle of the path. The second refinement step is to add values ββto the 1/4 and 3/4 tags.

Elementary quadrature algorithms include the addition of sequential refinement steps. It is convenient to encapsulate this function in the Quadrature structure:
struct Quadrature {
Then the Trapzd structure Trapzd obtained from this as follows:
template<class T> struct Trapzd: Quadrature { Doub a, b, s;
Using:
The Trapzd can be used in several ways. The simplest and toughest is the integration of the function according to the extended trapezoidal rule, where you know in advance the number of steps that you want. if you want 2^M + 1 , you can accomplish this with a snippet:
Ftor func; // Functor func here has no parameters. Trapzd<Ftor> s(func, a, b); for(j = 1 ;j <= m + 1; j++) val = s.next();
with the answer returned as val . Here Ftor is a functor containing an integrable function.
Bonus:
It is much better, of course, to clarify the trapezoid rule until a degree of accuracy is determined. For this function:
template<class T> Doub qtrap(T &func, const Doub a, const Doub b, const Doub eps = 1.0e-10) {
Type definitions.
typedef double Doub;
Ziezi source share