Skip to main content

Module integrate

Module integrate 

Source
Expand description

Numerical integration.

Gauss–Legendre quadrature, applied adaptively. A kernel integrates for arc length, for area and volume over a parametric patch, and for the moments that follow from those: all integrands that are smooth almost everywhere and awkward exactly where a feature is.

§Why Gauss rather than Simpson

An n-point Gauss rule is exact for polynomials of degree 2n - 1, against Simpson’s 3 for the same three evaluations. Since a B-spline is a piecewise polynomial and the speed of a curve along one is a square root of a polynomial, the integrands here are close enough to polynomial that the difference is large. Ten points integrate most spans to machine precision in one go.

§Why adaptive on top

A fixed rule cannot report its own error. A Gauss–Kronrod pair can: the fifteen-point Kronrod rule shares the seven-point Gauss rule’s nodes, so one pass over an interval yields two estimates, and their difference is a fair measure of what the better one still misses. Where that is inside the budget the estimate has converged there; where it is not, only that part is subdivided. So a curve that is straight over most of its length and sharp in one place costs what the sharp place costs, not what the sharp place would cost applied everywhere. The same pair, in tensor form, integrates over a rectangle of parameters the same way.

The recursion is bounded, and a result that hit the bound says so rather than being returned as though it converged.

Functions§

gauss_kronrod
Integrate f over [a, b] with the seven-point Gauss and fifteen-point Kronrod pair: the Kronrod value, and the magnitude of its difference from the Gauss value as the estimate of what it still misses.
gauss_legendre
Integrate f over [a, b] with the fixed ten-point rule.
gauss_legendre_rule
The ten-point Gauss-Legendre rule on [a, b]: each node with its weight.
integrate
Integrate f over [a, b] to an absolute tolerance.
integrate_2d
Integrate f(u, v) over the rectangle [a, b] x [c, d] to an absolute tolerance: a patch’s area, its moments, anything spread over a chart.