Quadrature rule (source code)

= Quadrature rule
{title2=$Q(f)=\sum_{i=1}^{m}w_i f(x_i)$}

A <quadrature rule> approximates an <integral> by a finite weighted sum of sampled <function> values:
$$
I_\rho(f)=\int_a^b\rho(x)f(x)\,dx\approx Q(f)=\sum_{i=1}^m w_i f(x_i).
$$
The <quadrature nodes> $x_i$ specify where to sample, and the <quadrature weights> $w_i$ specify how much each sample contributes. The density $\rho(x)$ specifies the target <integral>, whereas the discrete <quadrature weights> belong to the approximation. Ordinary <numerical integration> has $\rho=1$. <Gaussian quadrature> and the <midpoint quadrature rule> choose interior <quadrature nodes>; the <trapezoidal rule> includes endpoints.<NIST Digital Library of Mathematical Functions/3.5 Quadrature, subsection (iv) Interpolatory Quadrature Rules>[§3.5(iv), equation 3.5.15 and the following discussion of nodes and weights]{ref}

For ordinary <numerical integration>, exactness on the <constant function> $1$ requires $\sum_iw_i=b-a$; exactness on $x$ additionally requires $\sum_iw_ix_i=(b^2-a^2)/2$. These two checks make the <quadrature rule> exact for every <affine function>. For example, both the <midpoint quadrature rule> and <trapezoidal rule> give $6$ for $\int_0^2(2x+1)\,dx$. Testing progressively higher <polynomial degrees> defines the <degree of precision of a quadrature rule>. Exactness describes a class of <integrands>, rather than promising exact results for every <function>.

<Composite midpoint quadrature rules> and <composite trapezoidal rules> apply a simple <quadrature rule> on every panel of a <partition of an interval>. This buys accuracy by shrinking the panels while keeping the elementary formula fixed. For <continuous functions> sampled exactly, their <quadrature errors> tend to zero as the largest panel width tends to zero. The familiar second-order bounds require stronger assumptions about <derivatives>. The signed <approximation error> used here is $Q(f)-I_\rho(f)$; some sources define <quadrature error> with the opposite sign, so the convention must accompany any formula.