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$.
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)