Least-squares polynomial in an orthogonal-polynomial basis
= Least-squares polynomial in an orthogonal-polynomial basis
For orthogonal polynomials $Q_0,\ldots,Q_n$ under a positive weighted integral inner product, the least-squares approximation to $f$ of degree at most $n$ is
$$
p_n^*=\sum_{k=0}^n\frac{\langle f,Q_k\rangle}{\langle Q_k,Q_k\rangle}Q_k.
$$
Its residual is orthogonal to every polynomial of degree at most $n$.