Composite midpoint quadrature rule (source code)

= Composite midpoint quadrature rule
{title2=$M_n(f)=h\sum_{j=0}^{n-1}f(a+(j+1/2)h)$}

= Composite midpoint rule
{synonym}

Apply the <midpoint quadrature rule> on each of $n$ equal panels of a <partition of an interval>, with $h=(b-a)/n$:
$$
M_n(f)=h\sum_{j=0}^{n-1}f\left(a+(j+\tfrac12)h\right).
$$
Each <quadrature node> is a panel midpoint and each <quadrature weight> is $h$. For $f\in C^2[a,b]$, put $K=\max_{x\in[a,b]}|f''(x)|$. Summing the panel <quadrature errors> gives
$$
M_n(f)-I(f)=-\frac{b-a}{24}h^2f''(\xi),\qquad |M_n(f)-I(f)|\leq\frac{b-a}{24}h^2K
$$
for some $\xi\in(a,b)$. Each panel contributes at most $Kh^3/24$; there are $n=(b-a)/h$ panels, explaining the <composite midpoint rule error> of order $O(h^2)$ in <big O notation>. On a nonuniform <partition of an interval> with panel widths $h_j$ and largest width $H$, the corresponding bound is $K\sum_jh_j^3/24\leq K(b-a)H^2/24$.

For $f(x)=x^2$ on $[0,1]$, summing the sampled <polynomial> exactly yields
$$
M_n(f)=\frac13-\frac{1}{12n^2}.
$$
Doubling $n$ divides the <absolute error> by exactly four. For a general $C^2$ <function>, halving $h$ divides the displayed error bound by four, but the actual <absolute error> need not follow that ratio: cancellation can make it smaller or zero. <Continuous functions> still give convergence as the largest panel width tends to zero, by <uniform continuity>; without the bounded second <derivative>, the second-order rate is not guaranteed. <Noise sensitivity of a quadrature rule> explains a separate limitation when samples are inexact.