numerics
Loading...
Searching...
No Matches
quadrature.hpp
Go to the documentation of this file.
1/// @file quadrature.hpp
2/// @brief Numerical integration (quadrature) on [a, b]
3#pragma once
4
5#include "analysis/types.hpp"
6#include "core/policy.hpp"
7
8namespace num {
9
10/// @brief Trapezoidal rule with n panels
11/// @param backend Backend::omp parallelises the panel sum
12real trapz(ScalarFn f, real a, real b, idx n = 100,
13 Backend backend = Backend::seq);
14
15/// @brief Simpson's 1/3 rule with n panels (n must be even)
16/// @param backend Backend::omp parallelises the panel sum
17real simpson(ScalarFn f, real a, real b, idx n = 100,
18 Backend backend = Backend::seq);
19
20/// @brief Gauss-Legendre quadrature (exact for polynomials up to degree 2p-1)
21/// @param f Integrand
22/// @param a Lower bound
23/// @param b Upper bound
24/// @param p Number of quadrature points (1 to 5 supported)
26
27/// @brief Adaptive Simpson quadrature
28/// @param f Integrand
29/// @param a Lower bound
30/// @param b Upper bound
31/// @param tol Absolute error tolerance
32/// @param max_depth Maximum recursion depth
34 real tol = 1e-8, idx max_depth = 50);
35
36/// @brief Romberg integration (Richardson extrapolation on trapezoidal rule)
37/// @param f Integrand
38/// @param a Lower bound
39/// @param b Upper bound
40/// @param tol Convergence tolerance
41/// @param max_levels Maximum refinement levels
43 real tol = 1e-10, idx max_levels = 12);
44
45} // namespace num
Common function type aliases for the analysis module.
real trapz(ScalarFn f, real a, real b, idx n=100, Backend backend=Backend::seq)
Trapezoidal rule with n panels.
double real
Definition types.hpp:10
Backend
Selects which backend handles a linalg operation.
Definition policy.hpp:19
@ seq
Naive textbook loops – always available.
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.
std::size_t idx
Definition types.hpp:11
real gauss_legendre(ScalarFn f, real a, real b, idx p=5)
Gauss-Legendre quadrature (exact for polynomials up to degree 2p-1)
constexpr real e
Definition math.hpp:41
real adaptive_simpson(ScalarFn f, real a, real b, real tol=1e-8, idx max_depth=50)
Adaptive Simpson quadrature.
real simpson(ScalarFn f, real a, real b, idx n=100, Backend backend=Backend::seq)
Simpson's 1/3 rule with n panels (n must be even)
std::function< real(real)> ScalarFn
Real-valued scalar function f(x)
Definition types.hpp:11
real romberg(ScalarFn f, real a, real b, real tol=1e-10, idx max_levels=12)
Romberg integration (Richardson extrapolation on trapezoidal rule)
Backend enum for linear algebra operations.