# 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.

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$)

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.

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} .$$

• i have used integration by parts but my answer is extremely long! i have put it into wolfram alpha just now and also a very very long answer.. – Bernard.Mathews Dec 11 '13 at 22:30
• @Bernard.Mathews: Maybe it is easier for you to deal with the exponential, so you can use the identity $\cos(nx) = \frac{e^{i nx}-e^{-inx}}{2}$ and split the integral. – Mhenni Benghorbal Dec 11 '13 at 22:36

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)$$

• thanks for your answer... i have the solution in the book as $$\frac{\pi^2}{12}+ \sum_{k=1}^\infty \frac{\cos(nx)}{n^2}$$ how would i show it like this? – Bernard.Mathews Dec 11 '13 at 22:31
• No there is a mistake in your working out! where you have done $a_n$ it is actually $\pi - x$ and not $x+\pi$ The book is definately right it is Calculus of several variables by Lang, page 502 – Bernard.Mathews Dec 11 '13 at 22:45
• Sorry I just found where my mistake was. But it has nothing to do with the change of variable $u=x-\pi$. – Mercy King Dec 11 '13 at 23:00
• haha no worries i thought you might! Not often i spot mistakes to be honest.. Many thanks for your help :) – Bernard.Mathews Dec 11 '13 at 23:01