Skip to content

num::simpson

Defined in header <quadrature/quadrature.hpp>

template <bool Parallel = false, typename Float = double,
          std::invocable<Float> Func = scalar_fn>
Float simpson(Func &&f, Float a, Float b, idx n = 100);

Composite Simpson's 1/3 numerical integration with \(n\) panels (\(n\) even).

Approximates \(\int_a^b f(x)\,\mathrm{d}x\) using piecewise quadratic polynomials, achieving \(\mathcal{O}(h^4)\) error.

Template parameters

  • Float: Floating point scalar type.
  • Func: Integrand callable Float(Float x).
  • Parallel: Thread the panel sum with OpenMP (default: sequential).

Parameters

  • f: Integrand function.
  • a: Lower limit.
  • b: Upper limit.
  • n: Number of panels (must be even, default: 100).

Return value

Approximated integral value.

Exceptions

  • std::invalid_argument: If n is not even.

See also

trapz, adaptive_simpson, gauss_legendre