Find Fourier Series of $f(x)=e^x+e^{-x}$ Problem:
Let $f:\mathbb{R}\to\mathbb{R}$ be a function such that:


*

*$f(x)=e^x+e^{-x},\ \ \forall\ \ x \in [-\pi, \pi)$ and

*$f(x+2\pi)=f(x),\ \ \forall\ \ x \in \mathbb{R}.$


Calculate the Fourier series of $f$.
What I've done:
First, I attempt to calculate the Fourier Coefficients.


*

*Trying to find $a_0$:


$$
\begin{align}
a_0
& =\frac{1}{2\pi}\int_{-\pi}^{\pi}{f(x)dx}
=\frac{1}{\pi}\int_{0}^{\pi}{f(x)dx}
=\frac{1}{\pi}\int_{0}^{\pi}{(e^x+e^{-x})dx}
=\frac{1}{\pi}\left[e^x-e^{-x}\right]_{0}^{\pi}\\
& =\frac{1}{\pi}(e^{\pi}-1-e^{-\pi}+1)
=\frac{e^{\pi}-e^{-\pi}}{\pi}
=\frac{2\sinh(\pi)}{\pi}
\end{align}
$$


*Trying to find $a_n$:


$$
\begin{align}
a_n
& =\frac{1}{\pi}\int_{-\pi}^{\pi}{f(x)\cos(nx)dx}
=\frac{2}{\pi}\int_{0}^{\pi}{f(x)\cos(nx)dx}
=\frac{2}{\pi}\int_{0}^{\pi}{(e^x+e^{-x})\cos(nx)dx}\\
& =\frac{2}{\pi}\int_{0}^{\pi}{e^x\cos(nx)dx}
  +\frac{2}{\pi}\int_{0}^{\pi}{e^{-x}\cos(nx)dx}
=I+J
\end{align}
$$

$$
\begin{align}
I
& =\frac{2}{\pi}\int_{0}^{\pi}{e^x\cos(nx)dx}
=\frac{2}{\pi}\left[e^x\cos(nx)\right]_{0}^{\pi}
+\frac{2n}{\pi}\int_{0}^{\pi}{e^x\sin(nx)dx}\\
& =\frac{2}{\pi}(e^{\pi}\cos(n\pi)-1)
  +\frac{2n}{\pi}\left[e^x\sin(nx)\right]_{0}^{\pi}
  -\frac{2n^2}{\pi}\int_{0}^{\pi}{e^x\cos(nx)dx}\\
& =\frac{2}{\pi}(e^{\pi}(-1)^n-1)
  +\frac{2n}{\pi}e^{\pi}\sin(n\pi)
  -n^2I
=\frac{2(e^{\pi}(-1)^n-1)}{(1+n^2)\pi}
\end{align}
$$

$$
\begin{align}
J
& =\frac{2}{\pi}\int_{0}^{\pi}{e^{-x}\cos(nx)dx}
=\ ...\ 
=\frac{2(1-e^{-\pi}(-1)^n)}{(1+n^2)\pi}
\end{align}
$$

$$
\begin{align}
a_n
& =I+J
=\frac{2(e^{\pi}(-1)^n-1)}{(1+n^2)\pi}
+\frac{2(1-e^{-\pi}(-1)^n)}{(1+n^2)\pi}
=\frac{2(e^{\pi}(-1)^n-e^{-\pi}(-1)^n)}{(1+n^2)\pi}\\
& =\frac{2(-1)^n(e^{\pi}-e^{-\pi})}{(1+n^2)\pi}
=\frac{4(-1)^n\sinh(\pi)}{(1+n^2)\pi}
\end{align}
$$


*Since $f$ is an even function, $b_n=\frac{1}{\pi}\int_{-\pi}^{\pi}{f(x)\sin(nx)dx}=0$.


After finding the Fourier Coefficients, I attempt to find the Fourie Series expression:
$$
\begin{align}
s(x)
& =a_0+\sum_{n=1}^{\infty}(a_n\cos(nx)+b_n\sin(nx))
=a_0+\sum_{n=1}^{\infty}a_n\cos(nx)\\
& =\frac{2\sinh(\pi)}{\pi}+\sum_{n=1}^{\infty}{\frac{4(-1)^n\sinh(\pi)}{(1+n^2)\pi}}\cos(nx)\\
& =\frac{2\sinh(\pi)}{\pi}+\frac{4\sinh(\pi)}{\pi}\sum_{n=1}^{\infty}{\frac{(-1)^n}{(1+n^2)}}\cos(nx)
\end{align}
$$
Question:
Is the approach I'm following and the result I've found correct? Is there a better way to tackle the above problem?
Edit:
As mentioned in a comment of mine under @Btzzzz's answer, what troubles me is the graph Desmos produces for my series, whose amplitude is stuck at $21.789$ while the graph of $f$ approaches $\infty$.
 A: This seems right to me but I think that using the complex coefficient will be easier:
$$f(x)=\sum_{n=-\infty}^\infty a_n e^{inx};\quad a_n=\frac1{2\pi}\int_{-\pi}^\pi f(x)e^{-inx}\;dx$$Where $i$ is the imaginary unit.
Let's calculate $a_n$ shall we:

$$\int_{-\pi}^\pi (e^x+e^{-x})e^{-inx}\;dx=\int_{-\pi}^\pi 2 e^{-i n x} \cosh(x)\;dx=\cdots= \dfrac{i e^{-(1 + i n) x} ((n - i) e^{2 x} + n + i)}{n^2 + 1}{\LARGE|}_{-\pi}^\pi\\=\dfrac{4 (\sinh(\pi) \cos(\pi n) + n \cosh(\pi) \sin(\pi n))}{n^2 + 1}$$
We can simplify it by remembering that $n\in\Bbb N$ so $\sin(\pi n)=0,\cos(\pi n)=(-1)^n$:$$\dfrac{4 (\sinh(\pi) \color{blue}{\cos(\pi n)} + \color{red}{n \cosh(\pi) \sin(\pi n)})}{n^2 + 1}=\dfrac{4 \sinh(\pi)(-1)^n}{n^2 + 1}$$
Now dividing by $2\pi$ to get: $$a_n=\frac2{\pi}\dfrac{ \sinh(\pi)(-1)^n}{n^2 + 1}$$

In the end we get the sum $$f(x)=\sum_{n=-\infty}^\infty (-1)^n\frac2\pi\dfrac{ \sinh(\pi)}{n^2 + 1}e^{inx}$$
A: Your solution is correct, these kind of calculations are often long and tedious so there is no general shortcut. Something i like to use to verify my solution is correct is by plotting the series using Desmos and comparing it to the graph of $f$. (Noting that it won't be exact since this is just an approximation of the function)
