Fourier series question, stuck on the integration [EDIT]: The correct solution is definately $$ \frac{\pi^2}{12}+ \sum_{k=1}^\infty \frac{\cos(nx)}{n^2} $$ from the book Calculus of several variables, by Lang (Springer) Please can you make sure this is the answer you give as it is definately correct. Many thanks
I have a question on fourier series which i am a bit confused about. 
Find the fourier series of the $2\pi$-periodic function defined by $f(x)=\frac{( \pi-x)^2}{4}$ for $0\leq x\leq2\pi$.
So i have 
$$f(x)={a_0\over2}+\sum_{k=1}^\infty ( a_n \cos(nx) +b_n\sin(nx) dx$$
with
$a_0={1\over\pi}\int_0^{2\pi} f(x) dx $  
$a_n={1\over\pi}\int_0^{2\pi} f(x)\cos(nx)\ dx= $
$b_n={1\over\pi}\int_0^{2\pi} f(x)\sin(nx)\ dx= $
So with some working out i have 
$$a_0={1\over\pi}\int_0^{2\pi} f(x) dx =\frac{-2\pi^2}{12}$$
 but 
$$a_n={1\over\pi}\int_0^{2\pi} f(x)\cos(nx)\ dx ={1\over\pi}\int_0^{2\pi} \frac{( \pi-x)^2}{4}\cos(nx)\ dx$$
is giving me the longest answer ever which i am pretty sure it uncorrrect. 
I have that the correct solution is $$ \frac{\pi^2}{12}+ \sum_{k=1}^\infty \frac{\cos(nx)}{n^2} $$
and when i put my $a_n$ and $b_n$ in i get something completely different.
Could someone please help me get to this answer? 
Many thanks in advance 
 A: For example,for $a_n$, $n\geq 1$ we have that $$a_n={1\over\pi}\int_0^{2\pi} f(x)\cos(nx)\ dx=\frac {2}{\pi}\int _{0}^{\pi} \frac {(\pi-x)^2}{4}\cos nxdx=\frac {1}{2\pi}\cdot (\pi-x)^2\cdot \frac {\sin nx}{n}$$(from $0$ to $\pi$)+$$\frac {1}{\pi n}\cdot \int_{0}^{\pi} (\pi-x)\sin nxdx=\frac {1}{\pi n}\cdot \frac {(\pi-x)\cos nx}{n}$$ (from $0$ to $\pi $)
A: For $n\geq 1$:
$$a_n={1\over\pi}\int_0^{2\pi} f(x)\cos(nx)\ dx ={1\over\pi}\int_0^{2\pi} \frac{( \pi-x)^2}{4}\cos(nx)\ dx={1\over\pi}\int_0^{2\pi} \frac{\pi^2}{4}\cos(nx)\ dx-\\
{1\over\pi}\int_0^{2\pi} \frac{\pi x}{2}\cos(nx)\ dx+
{1\over\pi}\int_0^{2\pi} \frac{ x^2}{4}\cos(nx)\ dx;
$$
the first integral vanishes; the last two are tackled using integration by parts (taking care of coefficients and prefactors), i.e.
$$\int x\cos x dx=x\sin x+\cos x+C $$
$$\int x^2\cos x dx=(x^2-2)\sin x +2x\cos x+C'. $$
For $b_n$ the methodology is analogous.
A: Hint: Make the change of variables $\pi-x=u$, this will show you that $b_n =0$, since the integrand is an odd function

$$ b_n =(-1)^{n+1} \int _{-\pi }^{\pi }\!{u}^{2}\sin \left( nu \right) {du}
=0. $$ 

For $a_n$, you need integration by parts, so you should take your time to evaluate the integral. Another approach is to use the identity

$$ \cos(nx) = \frac{e^{i nx}-e^{-inx}}{2} . $$   

A: We have
\begin{eqnarray}
a_0&=&\frac1\pi\int_0^{2\pi}f(x)\,dx=\frac{1}{4\pi}\int_0^{2\pi}(x-\pi)^2\,dx=\frac{(x-\pi)^3}{12\pi}\Big|_0^{2\pi}=\frac{2\pi^3}{12\pi}=\frac{\pi^2}{6},\\
a_n&=&\frac1\pi\int_0^{2\pi}f(x)\cos(nx)\,dx=\frac{1}{4\pi}\int_{-\pi}^\pi f(x+\pi)\cos(nx+n\pi)\,dx=\frac{(-1)^n}{4\pi}\int_{-\pi}^\pi x^2\cos(nx)\,dx\\
&=&\frac{(-1)^n}{2n\pi}\int_0^\pi x^2(\sin(nx))'\,dx=-\frac{(-1)^n}{n\pi}\int_0^\pi x\sin(nx)\,dx\\
&=&\frac{(-1)^n}{\pi n^2}x\cos(nx)\Big|_0^\pi
-\frac{(-1)^n}{\pi n^2}\int_0^\pi\cos(nx)\,dx=\frac{(-1)^n}{\pi n^2}\pi\cos(n\pi)=\frac{1}{n^2},\\
b_n&=&\frac1\pi\int_0^{2\pi}f(x)\sin(nx)\,dx=\frac{1}{4\pi}\int_{-\pi}^\pi f(x+\pi)\sin(nx+n\pi)\,dx=\frac{(-1)^n}{4\pi}\int_{-\pi}^\pi x^2\sin(nx)\,dx\\
&=&0.
\end{eqnarray}
Thus the Fourier series of $f$ is given by
$$
\frac{\pi^2}{12}+\sum_{n=1}^\infty\frac{1}{n^2}\cos(nx)
$$
