Skip to main content

Crate integrate

Crate integrate 

Source
Expand description

A lightweight Rust library for numerical integration of real-valued functions.

integrate approximates definite integrals of the form

$$\int_a^b f(x)\, dx$$

using Newton-Cotes formulas, Gaussian quadrature, Romberg’s method, and adaptive techniques.

§Methods

§Newton-Cotes (newton_cotes)

FunctionDescription
newton_cotes::rectangle_ruleMidpoint rectangle rule
newton_cotes::trapezoidal_ruleTrapezoidal rule
newton_cotes::simpson_ruleSimpson’s 1/3 rule
newton_cotes::newton_ruleNewton’s 3/8 rule

§Gaussian Quadrature (gauss_quadrature)

FunctionDescription
gauss_quadrature::legendre_ruleGauss-Legendre rule
gauss_quadrature::gauss_laguerre_ruleGauss-Laguerre rule
gauss_quadrature::gauss_hermite_ruleGauss-Hermite rule
gauss_quadrature::gauss_first_kind_chebyshev_ruleGauss-Chebyshev rule (first kind)
gauss_quadrature::gauss_second_kind_chebyshev_ruleGauss-Chebyshev rule (second kind)

§Adaptive Quadrature (adaptive_quadrature)

FunctionDescription
adaptive_quadrature::adaptive_simpson_methodAdaptive Simpson’s method

§Romberg (romberg)

FunctionDescription
romberg::romberg_methodRomberg integration

§Quick Start

use integrate::prelude::*;
let result = trapezoidal_rule(|x: f64| x.exp(), 0.0, 1.0, 1000_usize);
assert!((result - (std::f64::consts::E - 1.0)).abs() < 1e-6);

§Caveats

All of the numerical integration techniques listed above assume that the integrand is continuous on the interval of integration. The error estimates generally require that the integrands are differentiable of whatever order is required so that the formula for the error estimate makes sense. Below is a checklist to verify before using any of these algorithms.

§Integrand checklist

  • Are there any singularities of the integrand in the interval of integration?

    • If there are, then can they be removed?

    • A function which has jump discontinuities can be integrated by splitting the interval of integration into subintervals on which the function is continuous, then numerically integrating over each subinterval and summing the results.

    • Using integration by parts, certain types of singular integrals can be expressed as the sum of a closed-form term and a non-singular integral.

    • In other cases, an approximation of the integral in a small neighborhood of the singularity can be obtained analytically, and the interval of integration can be split so that numerical integration is used on the non-singular parts.

  • Does the function oscillate over the region of integration? If so, make sure that the step size is smaller than the wavelength of the function. The interval can also be split into subintervals of half a wavelength each.

Modules§

adaptive_quadrature
Adaptive Simpson quadrature for numerical integration.
gauss_quadrature
Gaussian quadrature rules for numerical integration.
newton_cotes
Newton-Cotes quadrature rules for numerical integration.
prelude
Convenience re-exports of all public integration functions.
romberg
Romberg’s method for numerical integration via Richardson extrapolation.