Represent $\cos(x)$ as a sum of sines - where is my mistake Let's look at $f(x)=\cos(x)$ defined on the interval $[0,\pi]$.
We know that for any function $g$ defined on $[0,\pi]$ we have:
$g(x)=\sum_{k=1}^{\infty}B_k\sin(kx)$ where $B_k=\frac{2}{\pi}\int_{0}^{\pi}g(x)\sin(kx)dx$. And $f$ is no different. So in our case:
$B_k=\frac{2}{\pi}\int_{0}^{\pi}f(x)\sin(kx)dx=\frac{2}{\pi}\int_{0}^{\pi}\cos(x)\sin(kx)dx$
It can be shown that $\int\cos(x)\sin(kx)dx=\frac{\sin(x)\sin(kx)+k\cos(x)\cos(kx)}{1-k^2}$, so:
$B_k=\frac{2}{\pi}\int_{0}^{\pi}\cos(x)\sin(kx)dx=\frac{2}{\pi}\frac{-k\cos(k\pi)-k}{1-k^2}=\frac{2}{\pi}\frac{(-1)^{k+1}k-k}{1-k^2}$
So overall we should have $f(x)=\cos(x)=\sum_{k=1}^{\infty}\frac{2}{\pi}\frac{(-1)^{k+1}k-k}{1-k^2}\sin(kx)$ But that clearly can't be true, because $\cos(0)=1$ but that sum is equal to $0$ at $x=0$ since $\sin(0)=0$.
Where is the mistake? and not only that, we seem to have a big problem when $k=1$

Your formula after "it can be shown that" is clearly not valid for $k=1$,
so you simply have to compute $B_1$ using some different method. (For example, $\int \cos x \sin x \, dx= \frac12 \sin^2 x + C$.)
