|
Math::Integral::Romberg - scalar numerical integration |
Math::Integral::Romberg - scalar numerical integration
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);
# an alternative way of doing the long form
$Math::Integral::Romberg::rel_err = $rel_err;
$Math::Integral::Romberg::abs_err = $abs_err;
$Math::Integral::Romberg::max_split = $max_split;
$Math::Integral::Romberg::min_split = $min_split;
$area = integral(\&f, $x1, $x2);
integral() numerically estimates the integral of f() using Romberg
integration, a faster relative of Simpson's method.
&$f(x) must be
finite at $x1 and $x2.
2**n + 1 points with the estimate computed using
2**(n-1) + 1 points.
Once $min_split has been reached (see below), computation stops as soon as relative error drops below $rel_err, absolute error drops below $abs_err, or $max_split is reached.
If not supplied, uses the value $Math::Integral::Romberg::rel_err whose default is 10**-10. A value of 10**-15 is close to the accuracy limits of double-precision floating point.
2 ** $max_split + 1 different sample x values are used to
estimate the integral of f(). If not supplied, uses the value of
$Math::Integral::Romberg::max_split, which defaults to 16,
corresponding to 65537 sample points.
2 ** $min_split + 1 different sample x values are used to
estimate the integral of f(). If not supplied, uses the value of
$Math::Integral::Romberg::max_split, which defaults to 5,
corresponding to 33 sample points.
integral() will return a two-element list, containing
the estimate followed by the number of sample points used to compute
the estimate.
Using the long form of integral() sets the convergence parameters
for that call only - you must use the package-qualified variable
names (e.g. $Math::Integral::Romberg::abs_tol) to change the values
for all calls.
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.
Eric Boesch (ebo@notes.dannet.dk)
|
Math::Integral::Romberg - scalar numerical integration |