Moment matching (source code)

= Moment matching

For a measure $\mu$ with <moments> $m_j=\int x^j\,d\mu(x)$, a <quadrature rule> $Q(f)=\sum_iw_if(x_i)$ is exact through <polynomial degree> $d$ precisely when
$$
\sum_iw_ix_i^j=m_j,\qquad0\leq j\leq d.
$$
Necessity follows by testing each <monomial>; sufficiency follows by <linearity> for any <polynomial>. These equations turn an integration requirement into algebraic constraints on the <quadrature nodes> and <quadrature weights>.

For ordinary integration on $[-1,1]$, the first <moments> are $m_0=2$, $m_1=0$, $m_2=2/3$ and $m_3=0$. Symmetric nodes $\pm a$ with equal <quadrature weights> $w$ therefore require $2w=2$ and $2wa^2=2/3$, giving $w=1$ and $a=1/\sqrt3$. Symmetry supplies the odd <moments>, producing the two-node <Gaussian quadrature> rule exact through degree three.