Skip to content

num::gauss_legendre

Defined in header <quadrature/quadrature.hpp>

template <typename Float = double, std::invocable<Float> Func = scalar_fn>
Float gauss_legendre(Func &&f, Float a, Float b, idx p = 5);

Gauss–Legendre quadrature with \(p \in [1, 5]\) optimal nodes.

Exact for all polynomials up to degree \(2p - 1\) using precomputed roots and weights of Legendre polynomials.

Template parameters

  • Float: Floating point scalar type.
  • Func: Integrand callable.

Parameters

  • f: Integrand function.
  • a: Lower integration limit.
  • b: Upper integration limit.
  • p: Number of quadrature nodes (\(1 \le p \le 5\), default: 5).

Return value

Exact or high-precision approximation of the integral.

Exceptions

  • std::invalid_argument: If p is not in range \([1, 5]\).