integrate

Integrate a function from a to b.

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.

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

Parameters

f Func

The function to integrate. This can be given as a function pointer, a delegate, or a struct/class which defines opCall().

a Real

The lower limit of integration.

b Real

The upper limit of integration.

epsRel Real

(optional) The requested relative accuracy.

epsAbs Real

(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.

Examples

// 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);

Meta