Refer to this OP: Sign of a series, we have the following equation
\begin{equation} \sum_{k=1}^{\infty}\frac{\sin kx}{k}=\frac{\pi-x}{2} \end{equation}
defined for $0\le x\le 2\pi$.
Here is my attempt to prove it: \begin{align} \sum_{k=1}^{\infty}\frac{\sin kx}{k}&=\sum_{k=1}^{\infty}\int\cos kx\,dx\\ &=\int\left(\sum_{k=1}^{\infty}\cos kx\right)\,dx\\ &=\int\left(\sum_{k=1}^{\infty}\frac{e^{ikx}+e^{-ikx}}{2}\right)\,dx\\ &=\frac{1}{2}\int\left(\frac{1}{1-e^{ix}}+\frac{1}{1-e^{-ix}}\right)\,dx\\ &=\frac{1}{2}x+C \end{align} Here is the problem:
To get the value of $C$, let $x=0$ and I get $C=0$, but if I let $x=\pi$ I get $C=-\frac{\pi}{2}$. Similarly, if I I let $x=2\pi$ I get $C=-\pi$. Where am I doing it wrongly? Could you please point out my mistake and guide me to prove the above equation? Any help would be greatly appreciated. Thank you.
Hint: $~\displaystyle\sum_{n=1}^\infty\frac{t^n}n=-\ln(1-t).~$ Now let $t=e^{ix}=\cos x+i\sin x$, and use de Moivre's formula.