pub fn gauss_legendre(n: usize) -> Result<QuadratureRule, ErrorsJSL>Expand description
The n-point Gauss-Legendre rule for ∫_{−1}^{1} f(x) dx, nodes ascending.
The nodes are the zeros of the Legendre polynomial P_n and the weights are
w_i = 2 / ((1 − x_i²) P_n'(x_i)²). The rule is exact for polynomials of degree 2n − 1.
Map it to [a, b] with x = (a + b)/2 + (b − a)/2 · t, or use GaussLegendreEngine.
use lib_jsl_integration::gaussian_quadrature::gauss_legendre;
let rule = gauss_legendre(3).unwrap();
// Three points integrate x⁴ exactly (degree 4 ≤ 2·3 − 1): ∫ x⁴ dx over [−1, 1] = 2/5.
assert!((rule.apply(|x| x.powi(4)) - 0.4).abs() < 1e-15);
// The weights sum to the length of the interval.
assert!((rule.weights.iter().sum::<f64>() - 2.0).abs() < 1e-15);