How to write a fourier series using periodic boundary conditions Would writing 
$$
f(x) = x^2
$$ 
as a Fourier series using periodic boundary conditions on $-L < x < L$ with a basis of 
$$
e^{\frac{i\pi nx}{L}}
$$
be just 
\begin{align}\bigl\langle e^{\frac{i\pi nx}{L}},x^{2}\bigr\rangle & = \Bigl\langle e^{\frac{i\pi nx}{L}},\sum_ma_mx^{2}\Bigr\rangle\\
&=\int_{-L}^Lx^{2}e^{\frac{i\pi nx}{L}}dx\\
&=\biggl[\frac{x^{2}}{\frac{in\pi}{L}}-\frac{2x}{(\frac{in\pi}{L})^{2}}+\frac{2}{(\frac{in\pi}{L})^{3}}\biggr]e^{\frac{i\pi nx}{L}}\Biggr|_{-L}^{L}
\end{align}

You should write
\begin{align}
c_n &= \langle x^2, e^{-in\pi x/L}\rangle\\ 
&= \frac{1}{2\pi}\int_{-L}^Lx^2\bigg(\cos\Big(\frac{n\pi x}{L}\Big) - \sin\Big(\frac{n\pi x}{L}\Big)\bigg)dx
\end{align}
Since $x^2\sin$ is an odd term, the sine terms integrate to zero so we are left with
$$
c_n = \frac{1}{\pi}\int_0^Lx^2\cos\Big(\frac{n\pi x}{L}\Big)dx = \frac{2\cos(n\pi)}{n^2} = \frac{2(-1)^n}{n^2}
$$
for $n\neq 0$.  When $n = 0$, we have $c_0 = \frac{\pi^2}{3}$. By the convergence theorem, $c_n = c_{-n}$ so
$$
x^2 = \frac{\pi^2}{3}+4\sum_{n=1}^{\infty}\frac{(-1)^n}{n^2}\cos\Big(\frac{n\pi x}{L}\Big)
$$

An interesting part to this Fourier series is that by using Parseval's identity for $x\in(-\pi, \pi)$ for $L$, we have
\begin{align}
\frac{\pi^4}{9}+2\sum_{n=1}^{\infty}\frac{4}{n^4} &= \frac{1}{\pi}\int_0^{\pi}x^4dx\\
 &= \frac{\pi^4}{5}\\
\sum_{n=1}^{\infty}\frac{1}{n^4} &= \frac{\pi^4}{90}\\
\zeta(4) &= \frac{\pi^4}{90}
\end{align}
