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.

Any hints? Thanks in advance.

• 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
• Yes, I know that. The solutions only work for $n>1$, and I have to find a separate solution for the case $n=1$. I've clarified that in the question. The thing is that my solution for $b_n$ (n $\neq 1) is different from my teacher's solution. I went through the process 3 times, and I still didn't found the problem. Thanks! – Jose Lopez Garcia Dec 2 '17 at 19:35 1 Answer I agree with Math Lover, I don't see anything wrong with your solution. Perhaps you should ask you teacher how they obtained theirs? It appears like theirs is wrong. Wolfram Alpha gives the first 3 terms of this series to be $$-\frac{\sin x}2+\frac43\sin 2x-\frac34\sin 3x+\cdots$$ i.e. the coefficients are $$b_1=-\frac12; \,\,b_2=\frac43;\,\,b_3=-\frac34.$$ Your teacher's solution gives $$b_2=-\frac23;\,\,b_3=\frac14,$$which disagree, while yours give the correct coefficients for$b_2,b_3\$.

• Thank you, I was thinking so hard why my solution would be wrong. I would have never though my teacher would be wrong, but it seems like he is. Thank you for your help :) – Jose Lopez Garcia Dec 2 '17 at 20:13
• No problem! In future, it can be helpful to check your solutions on online calculators such as wolfram alpha to see if you really are wrong. – John Doe Dec 2 '17 at 20:15
• You are right, I totally missed that tool. Thanks! – Jose Lopez Garcia Dec 2 '17 at 20:31