Function integrate

Integrate a function from a to b.

Result!Real integrate(Func, Real) (
  scope Func f,
  Real a,
  Real b,
  Real epsRel = cast(Real)1e-06,
  Real epsAbs = cast(Real)0
);

This module contains a lot of different integration routines, and integrate() aims to be a simple interface to some of these. Currently, it only calls the integrateQAGS() and integrateQAGI() routines, but this may change in the future. In particular, it should take into account whether a function is oscillatory, if it has discontinuities and singularities in the integration interval, and so on.

Parameters

NameDescription
f The function to integrate. This can be given as a function pointer, a delegate, or a struct/class which defines opCall().
a The lower limit of integration.
b The upper limit of integration.
epsRel (optional) The requested relative accuracy.
epsAbs (optional) The requested absolute accuracy.

Note

This function is different from the other integrateXXX() routines in this module in that it allows a and b to take on the special values Real.infinity and -Real.infinity, where Real is the floating-point type being used.

Example

// Let's integrate the function
//
//              log(x)
//     f(x) = ----------
//                     2
//            1 + 100 x
//
// from x=0 to x=infinity.

real f(real x)  { return log(x)/(1 + 100*x*x); }
auto result = integrate(&f, 0.0L, real.infinity, 0.001L);

real exact = -PI * log(10.0)/20.0;
assert (abs(result.value - exact) < result.error);