I am wondering how to find a closed-form expression for the fourier coefficients $a_n=\frac{(-1)^n}{n}$, i.e. I am looking for a function $f$ on $(-\pi,\pi)$ that generates the fourier series
$$f(x)=\sum_n \frac{(-1)^n}{n} \cos(nx)$$
What I know from this source is the fact that the function
- should be even
- should be linear because the Fourier coefficients of $x^k$ involve $\frac{1}{n^k}$.
But if $f$ is even and should be linear, it can only be a constant function. So I am not sure if it is not possible or I made a mistake.
The graph looks like a half-circle and diverges for $x = \pm \pi$ because $f(\pm \pi)=\sum_n \frac{(-1)^n}{n}$
A similar post is this.
Just for the sake of completness:
We have $$f(x)=\sum_{n=1}^\infty \frac{(-1)^n}{n} \cos(nx)=\Re\left(\sum_{n=1}^\infty \frac{1}{n}e^{i\pi n}e^{ixn}\right)=\Re\left(\sum_{n=1}^\infty \frac{1}{n}e^{i(x+\pi)n}\right)=\Re\left(\sum_{n=1}^\infty \frac{1}{n}z^n\right)$$ with $z=e^{i(x+\pi)}$.
If we take the derivative, we get a geometric series $$f'(x)=\Re\left(\sum_{n=1}^\infty z^{n}\right)=\Re\left(\frac{1}{1-z}\right).$$
So we get $f$ by integrating $$f(x)=\Re\left(-\ln(1-z)\right)+c.$$ Since $f(0)=\sum_{i=0}^\infty \frac{(-1)^n}{n}=-\ln(2)$ we can conclude that $c=0$. So we are left with $$f(x)=-\Re\left(\ln(1-z)\right)=-\Re\left(\ln(1-e^{i(x+\pi)})\right)=-\Re\left(\ln(1+e^{ix})\right).$$ Using this post with $x=1+\cos(x)$ and $y=\sin(x)$ we can rewrite the $\ln$-expression: $\ln(1+e^{ix})=\ln(\sqrt{2\cos(x)+2})+i\theta$ and we get the final result $$f(x)=-\frac{1}{2} \ln\left(2(\cos(x)+1)\right)=-\ln(2\cos(\frac{x}{2})).$$