#include <trapezoid.h>
Public Member Functions | |
trapezoidal_integrator (Function &f, unsigned int iterations=100, double relative_error=1.0e-13) | |
~trapezoidal_integrator () | |
double | integrate (double a, double b) |
For example, to evaluate definite integrals for sine, first a trapezoidal integrator is created providing a target function functor:
typdef double Function(double);
num::trapezoidal_integrator<Function> integrator(std::sin);
Then, evaluating definite integrals is accomplished using the integrate
method:
// integrate sine from 0 to Pi.
double two = integrator.integrate(0.0, num::PI);
integrate sine from Pi/2 to 2 Pi. double one = integrator.integrate(num::PI / 2.0, num::PI);
References:
trapezoidal_integrator< Function >::trapezoidal_integrator | ( | Function & | f, | |
unsigned int | iterations = 100 , |
|||
double | relative_error = 1.0e-13 | |||
) | [inline] |
Create an integrator for the given function.
f | the function functor. | |
iterations | the maximum number of iterations. | |
relative_error | the maximum allowable relative error. |
trapezoidal_integrator< Function >::~trapezoidal_integrator | ( | ) | [inline] |
Destructor.
double trapezoidal_integrator< Function >::integrate | ( | double | a, | |
double | b | |||
) | [inline] |
Evaluate the definite integral from a
to b
.
a | the lower limit of integration. | |
b | the upper limit of integration. |
a
to b
.