trapezoidal_integrator< Function > Class Template Reference

#include <trapezoid.h>

Inheritance diagram for trapezoidal_integrator< Function >:

iterative_method

List of all members.

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)


Detailed Description

template<class Function>
class trapezoidal_integrator< Function >

The extended trapezoidal rule for numerically integrating functions.

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:

  1. Eric W. Weisstein. "Newton-Cotes Formulas." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Newton-CotesFormulas.html
  2. Eric W. Weisstein. "Trapezoidal Rule." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/TrapezoidalRule.html

Constructor & Destructor Documentation

template<class Function>
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.

Parameters:
f the function functor.
iterations the maximum number of iterations.
relative_error the maximum allowable relative error.

template<class Function>
trapezoidal_integrator< Function >::~trapezoidal_integrator (  )  [inline]

Destructor.


Member Function Documentation

template<class Function>
double trapezoidal_integrator< Function >::integrate ( double  a,
double  b 
) [inline]

Evaluate the definite integral from a to b.

Parameters:
a the lower limit of integration.
b the upper limit of integration.
Returns:
the definite integral from a to b.


The documentation for this class was generated from the following file:
Generated on Wed Nov 21 22:22:16 2007 for numerics4c++ by  doxygen 1.5.3