# Fourier series of $f(x)=x\cos(x)$

I'd like to calculate the fourier series of $f(x)=x\cos(x)$, with $x\in(-\pi,\,\pi)$.

My solution, however, doesn't agree with my teacher's solution. So either I went wrong somewhere (most likely), or it was him who went wrong (but I don't think so).

So, $$f(x)=a_0+\sum_{n=1}^\infty\left(a_n\cos(nx)+b_n\sin(nx)\right)$$

I start by realising that $f(x)$ is an odd function, since $f(-x)=-f(x)$, and therefore the coefficients $a_0$ and $a_n$ will both equal $0$: $$a_0=a_n=0$$ Therefore, I'm left with: $$f(x)=\sum_{n=1}^\infty b_n\sin(nx)$$ And all I have to do now is calculate the coefficients $b_n$, and this is exactly where I'm going wrong.

Firstly I'll present my teacher's solution: $\boxed{b_n=\dfrac{2(-1)^{n+1}}{n^2-1}}$ ($n\neq1$)

Now I'll show you what I'm doing: $$b_n=\dfrac2\pi\int_0^\pi x\cos(x)\sin(nx)dx$$ Integrating by parts: $$\begin{cases} u = x & \Rightarrow du=dx\\ dv = \cos(x)\sin(nx)dx & \Rightarrow v=-\dfrac12\left(\dfrac{\cos x(n+1)}{n+1}+\dfrac{\cos x(n-1)}{n-1}\right) \end{cases}$$ Where $v$ was obtained via integration by parts. So: $$b_n=\dfrac2\pi\left(uv\vert_0^\pi-\int_0^\pi vdu\right)$$ Where the last integral equals $0$. Therefore I get: $$\boxed{b_n=\dfrac{2n(-1)^{n+1}}{1-n^2}}\,(n\neq1)$$ Because: $\cos [\pi(n+1)] = \cos [\pi(n-1)] = (-1)^{n+1}$

I don't know where I went wrong... In particular notice that in my solution I have an $n$ in the numerator, its sign is different from my teacher's solution.

• Note that both solutions are wrong at $n=1$ – Andrei Dec 2 '17 at 19:18
• Your solution is correct for $n \neq 1$. – Math Lover Dec 2 '17 at 19:30