Solution (source code)

= Solution

On a <partition of an interval> $a=x_0<x_1<\cdots<x_N=b$, apply the <trapezoidal rule> separately to each panel and add:
$$
\boxed{T_N(f)=\sum_{j=1}^N\frac{x_j-x_{j-1}}2\bigl(f(x_{j-1})+f(x_j)\bigr).}
$$
For uniform spacing $h=(b-a)/N$, this <composite trapezoidal rule> becomes
$$
\boxed{T_N(f)=h\left[\frac12f(a)+\sum_{j=1}^{N-1}f(a+jh)+\frac12f(b)\right].}
$$
Each interior sample occurs in two panels; their half-<quadrature weights> combine to $h$. The endpoint <quadrature weights> are $h/2$.