When approximating an even function with period $2\pi$ by a Fourier-cosine-Series with $m$ terms, it has the error $$E_m=\int_{-\pi}^\pi \left[f(x)-\frac{a_0}{2}-\sum_{n=1}^m a_n \cos(nx)\right]^2 dx$$
Now I have to find the $a_n$'s which minimize this error. I got to the point where: $$a_n=\frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\cos(nx) dx$$ But I am not sure how to proceed further.