I would like to apply Legendre polynomials to least square approximation. Therefore I would like the function:
$L_n (x)=\sum_{k=0}^n a_k P_k (x)$
to fit $f(x)$ defined over $[-1,1]$ in a least square sense.
We should minimize:
$I(a_0, ..., a_n)= \int_{-1}^1 [f(x) - L_n (x)]^2 \; dx\tag1$
and so we must set
$\frac{\partial I}{\partial a_r} = 0,\qquad r=0,1, \ldots,n\tag2$
Using equations $(1)$ and $(2)$
$\int_{-1}^1 P_r(x) \left[f(x) - \sum_{k=0}^n a_k P_k (x)\right]dx = 0,\qquad r=0,1, \ldots,n$
should be an equivalent term.
My question now is: why is that true?
I would be glad if someone could illustrate the last step with more details. Thanks, Rainier.