Numerical Integration

numerics4c++ provides the means to evaluate definite integrals through the use of common numerical methods. The following routines are available for numerical integration:

Method Description
Adaptive Integrator An implementation of Adaptive Quadrature.
Romberg Integrator An implementation of Romberg integration.
Simpson's Integrator An implementation of the extended Simpson's rule.
Trapezoidal Integrator An implementation of the extended trapezoidal rule.

Adaptive Integrator

The adaptive_integrator class provides an implementation of Adaptive Quadrature.

Evaluating definite integrals using adaptive quadrature involves creating an adaptive_integrator object for a particular functor object. Once, the integrator is created, definite integrals can be evaluated by calling the integrate method providing the limits of integration. Here is an example of evaluating integrals for sine:

typdef double Function(double);
 
num::adaptive_integrator<Function> integrator(std::sin);
  
// integrate sine from 0 to Pi.
double two = integrator.integrate(0.0, num::PI);

// integrate sine from Pi/2 to Pi.
double one = integrator.integrate(num::PI / 2.0, num::PI);

Romberg Integrator

The romberg_integrator class provides an implementation of Romberg Integration.

Evaluating definite integrals using Romberg integration involves creating an romberg_integrator object for a particular functor object. Once, the integrator is created, definite integrals can be evaluated by calling the integrate method providing the limits of integration. Here is an example of evaluating integrals for sine:

typdef double Function(double);
 
num::romberg_integrator<Function> integrator(std::sin);
  
// integrate sine from 0 to Pi.
double two = integrator.integrate(0.0, num::PI);

// integrate sine from Pi/2 to Pi.
double one = integrator.integrate(num::PI / 2.0, num::PI);

Simpson's Integrator

The simpsons_integrator class provides an implementation of the extended Simpson's rule.

Evaluating definite integrals using Simpson's rule involves creating an simpsons_integrator object for a particular functor object. Once, the integrator is created, definite integrals can be evaluated by calling the integrate method providing the limits of integration. Here is an example of evaluating integrals for sine:

typdef double Function(double);
 
num::simpsons_integrator<Function> integrator(std::sin);
  
// integrate sine from 0 to Pi.
double two = integrator.integrate(0.0, num::PI);

// integrate sine from Pi/2 to Pi.
double one = integrator.integrate(num::PI / 2.0, num::PI);

Trapezoidal Integrator

The trapezoidal_integrator class provides an implementation of the extended trapezoidal rule.

Evaluating definite integrals using the trapezoidal rule involves creating an trapezoidal_integrator object for a particular functor object. Once, the integrator is created, definite integrals can be evaluated by calling the integrate method providing the limits of integration. Here is an example of evaluating integrals for sine:

typdef double Function(double);
 
num::trapezoidal_integrator<Function> integrator(std::sin);
  
// integrate sine from 0 to Pi.
double two = integrator.integrate(0.0, num::PI);

// integrate sine from Pi/2 to Pi.
double one = integrator.integrate(num::PI / 2.0, num::PI);