This is my first step with Fourier series and I'm stuck at the beginning. So my solution:
The function $f(x)=\cos^2x$ is an even function. Thus I use formulas:
$a_0 = \frac{2}{\pi} \int _0 ^\pi \cos^2x\,\text dx$ (1)
$a_n = \frac{2}{\pi}\int _0^\pi \cos^2x \cos nx\,\text dx$ (2)
My solution of the first one:
$$a_0 = \frac{2}{\pi} \int _0 ^\pi \cos^2x\,\text dx = \frac{1}{\pi} \int _0 ^\pi(1 + \cos2x)\,\text dx = \left.\frac {1}{\pi} \left(x + \frac{1}{2}\sin2x\right) \right|_0^\pi = 1$$
With the second part I have a problem:
$$a_n = \frac{2}{\pi} \int _0 ^\pi \cos^2x \cos nx\,\text dx = \frac{1}{\pi} \int _0 ^\pi (\cos nx + \cos 2x \cos nx)\,\text dx= \frac{1}{\pi}\int _0^\pi (\cos nx + \frac{1}{2}(\cos (n+2)x + \cos (n-2)x))\,\text dx =\left. \frac{1}{\pi} \left(\frac {\sin nx}{n} + \frac {\sin(n+2)x}{2(n+2)} + \frac {\sin(n-2)x}{2(n-2)}\right)\right|_0^\pi = 0 $$
It doesn't look like $0$ is the right answer. Furthermore I'm suspicious of $(n-2)$ in the denominator it seems there isn't $a_2$ in the series.