NAME

Math::Integral::Romberg - single-variable numerical integration

SYNOPSIS

use Math::Integral::Romberg 'integral';
$area = integral(\&f, $x1, $x2);    # Short form
$area = integral                    # Long form
 (\&f, $x1, $x2, $rel_err, $abs_err, $max_split, $min_split);

DESCRIPTION

integral() numerically estimates the integral of f() using Romberg's method, a faster relative of Simpson's method.

Parameters

$f

A reference to the function to be integrated.

$x1
$x2

The two extreme values of the range to be integrated. &$f(x) must be finite at $x1 and $x2.

$rel_err

Maximum acceptable relative error (default: 10**-15, which is close to the accuracy limits of double-precision floating point). Estimates of relative and absolute error are based on a comparison of the estimate computed using 2**n + 1 points with the estimate computed using 2**(n-1) + 1 points.

Once $min_split has been reached, computation stops as soon as relative error drops below $rel_err, absolute error drops below $abs_err, or $max_split is reached.

$abs_err

Maximum acceptable absolute error (default: 10**-40).

$max_split

At most 2 ** $max_split + 1 different sample x values are used to estimate the integral of f().

$min_split

At least 2 ** $min_split + 1 different sample x values are used to estimate the integral of f().

$Math::Integral::Romberg::return_point_count

This value defaults to 0. If you set it to 1, then when invoked in a list context, integral() will return a two-element list, containing the estimate followed by the number of different x values used to compute the estimate.

$Math::Integral::Romberg::abort

This value is set to 1 if neither the $rel_err nor the $abs_err thresholds are reached before computation stops. Once set, this variable remains set until you reset it to 0.

About the Algorithm

Romberg integration uses progressively higher-degree polynomial approximations each time you double the number of sample points. For example, it uses a 2nd-degree polynomial approximation (as Simpson's method does) after one split (2**1 + 1 sample points), and it uses a 10th-degree polynomial approximation after five splits (2**5 + 1 sample points). Typically, this will greatly improve accuracy (compared to simpler methods) for smooth functions, while not making much difference for badly behaved ones.

AUTHOR

Eric Boesch (ebo@notes.dannet.dk)