Fourier cosine series of $e^x$ I am trying to find the even extension of $e^x$ in the following way:
$$e^x=a_0+\sum_\limits{n=1}^\infty a_n\cos\left(\frac{n\pi x}L\right)$$
Since the extension is piecewise smooth and $f(L)=f(-L)$ we can differentiate term-by-term:
$$e^x=-\sum_\limits{n=1}^\infty \left(\frac{n\pi }L\right) a_n\sin\left(\frac{n\pi x}L\right)$$ and differentiating once more 
$$e^x=-\sum_\limits{n=1}^\infty \left(\frac{n\pi }L\right)^2 a_n\cos\left(\frac{n\pi x}L\right)$$ 
Now comparing with the second derivative obtained with the original, one can see that $$a_0=0,\qquad  -\left(\frac{n\pi }L\right)^2a_n =a_n$$
But what is wrong with this? How can I find $a_n$
 A: Disclaimer: This is a partial answer, and does not find a value for $a_n$.
I think the problem with the above approach is that $$e^x=-\sum_\limits{n=1}^\infty \left(\frac{n\pi }L\right) a_n\sin\left(\frac{n\pi x}L\right)$$
is the Fourier series for the odd extension of $e^x$, which cannot be differentiated term-by-term because the odd extension of $e^x$ has a discontinuity at $x=0$ (we also no longer have $f(L)=f(-L)$):

A: Using the observation that @AirConditioner made, the Fourier even extension of the exponential function cannot be differentiated once more. However, using the theorem found on Haberman’s Partial Differential Equations (page 117, where I believe you can also find the proof):

If $f’(x)$ is piecewise smooth, then the Fourier sine series of a continuous function $f(x)$,
  $$f(x)\sim\sum_\limits{n=1}^\infty B_n\sin\left(\frac{n\pi x}{L}\right)$$
  cannot, in generale, be differentiated term by term. However,
  $$f’(x)\sim \frac1L\left[f(L)-f(0)\right]+\sum_{n=1}^\infty\left[\frac{n\pi}{L}B_n+\frac2L\left((-1)^nf(L)-f(0)\right)\right]\cos\left(\frac{n\pi x}{L}\right)$$

So based on this result we can express $e^x$ as:
$$e^x\sim \frac1L\left(e^L-1\right)+\sum_{n=1}^\infty\left[-\left(\frac{n\pi}{L}\right)^2a_n+\frac2L\left((-1)^ne^L-1\right)\right]\cos\left(\frac{n\pi x}{L}\right) $$
And comparing with the starting equation
$$\begin{cases}
a_0= \frac1L\left(e^L-1\right)\\
a_n=\frac2L\cdot\frac{(-1)^ne^L-1}{1+\left(\frac{n\pi}{L}\right)^2},\,\, n\geq 1
\end{cases}$$
Now that the coefficients have been found, you can just plug them in the original series.
Note: This is a subtle way of solving this problem; an easier way might be by simply applying the definition of finding coefficients of cosine series (which involves integration).
