Solution (source code)

= Solution

Integrate the <Lagrange interpolation polynomial> and exchange the <integral> with the finite sum:
$$
\int_a^bp(x)dx=\sum_{j=0}^nf(x_j)\int_a^b\ell_j(x)dx.
$$
Therefore the <interpolatory quadrature> weights are
$$
\boxed{w_j=\int_a^b\ell_j(x)dx=\int_a^b\prod_{k\ne j}\frac{x-x_k}{x_j-x_k}\,dx.}
$$
The resulting <quadrature rule> is exact for every <polynomial> of degree at most $n$, since its interpolant is itself. For a general continuous $f$, replacing $f$ by its interpolant supplies the approximation.