#quadrature #gaussian #integration #numeric

gauss-quad

Library for applying Gaussian quadrature to integrate a function

8 releases

0.1.8 Nov 21, 2023
0.1.7 Sep 3, 2023
0.1.5 May 26, 2021
0.1.4 Dec 2, 2019
0.1.2 Aug 14, 2019

#232 in Math

Download history 23/week @ 2023-12-11 64/week @ 2023-12-18 1/week @ 2023-12-25 4/week @ 2024-01-01 37/week @ 2024-01-08 7/week @ 2024-01-15 1/week @ 2024-01-22 31/week @ 2024-02-05 114/week @ 2024-02-12 88/week @ 2024-02-19 147/week @ 2024-02-26 79/week @ 2024-03-04 108/week @ 2024-03-11 57/week @ 2024-03-18 55/week @ 2024-03-25

311 downloads per month
Used in 7 crates (3 directly)

MIT/Apache

210KB
1K SLoC

gauss-quad

Latest Version Build Status codecov

The gauss-quad crate is a small library to calculate integrals of the type

$$\int_a^b f(x) w(x) \mathrm{d}x$$

using Gaussian quadrature.

To use the crate, the desired quadrature rule has to be included in the program, e.g. for a Gauss-Legendre rule

 use gauss_quad::GaussLegendre;

The general call structure is to first initialize the n-point quadrature rule setting the degree n via

 let quad = QUADRATURE_RULE::init(n);

where QUADRATURE_RULE can currently be set to calculate either:

QUADRATURE_RULE Integral
Midpoint $$\int_a^b f(x) \mathrm{d}x$$
Simpson $$\int_a^b f(x) \mathrm{d}x$$
GaussLegendre $$\int_a^b f(x) \mathrm{d}x$$
GaussJacobi $$\int_a^b f(x)(1-x)^\alpha (1+x)^\beta \mathrm{d}x$$
GaussLaguerre $$\int_{0}^\infty f(x)x^\alpha e^{-x} \mathrm{d}x$$
GaussHermite $$\int_{-\infty}^\infty f(x) e^{-x^2} \mathrm{d}x$$

For the quadrature rules that take an additional parameter, such as Gauss-Laguerre and Gauss-Jacobi, the parameters have to be added to the initialization, e.g.

 let quad = GaussLaguerre::init(n, alpha);

Then to calculate the integral of a function call

let integral = quad.integrate(a, b, f(x));

where a and b (both f64) are the integral bounds and the f(x) the integrand (fn(f64) -> f64). For example to integrate a parabola from 0..1 one can use a lambda expression as integrand and call:

let integral = quad.integrate(0.0, 1.0, |x| x*x);

If the integral is improper, as in the case of Gauss-Laguerre and Gauss-Hermite integrals, no integral bounds should be passed and the call simplifies to

let integral = quad.integrate(f(x));

Dependencies

~3MB
~57K SLoC