How to compute this definite integral with an infinite sum inside?

This integral resulted from trying to solve a physics problem about diffusion: $$\int^L_{-L}\sum_{n=1}^{\infty} \cos\Big( \frac{(2n-1)\pi}{L}x\Big)e^{-D\left(\frac{(2n-1)\pi}{L}\right)^2t}\;dx$$ I thought about interchanging the integral sign and the summation and then just having $$\sum_{n=1}^{\infty}e^{-D\left(\frac{(2n-1)\pi}{L}\right)^2t}\int^L_{-L} \cos\Big( \frac{(2n-1)\pi}{L}x\Big)\;dx$$ Since $$\int^L_{-L} \cos\Big( \frac{(2n-1)\pi}{L}x\Big)\;dx = \frac{2 L \sin (2 π n)}{π-2 π n}$$ then my original integral is just equal $0$. I don't know if interchanging the integral with the summation is allowed in this case but I've seen it done before.

EDIT: Here is the original problem:

$$\frac{dC}{dt} = D\frac{d^2C}{dx^2}$$ with $$C(L,t) = C(-L,t) \\ \frac{dC}{dx}(L,t) = \frac{dC}{dx}(-L,t) = 0 \\ C(x,0) = \delta(x)$$ The integral is not the final solution but rather part of it.

• Note that $\int f(x) + g(x) dx = \int f(x) dx + \int g(x) dx$. The integral is linear and can be "dispersed" into a summation. – Kaynex Nov 9 '16 at 3:27
• Could you tell us how you arrived at the above integral? – Jacky Chong Nov 9 '16 at 3:29
• You might want to read: math.stackexchange.com/q/188567/9464 – Jack Nov 9 '16 at 3:34
• @JackyChong It results from solving the heat equation in one dimension with homogeneous boundary conditions and an initial condition equal to the Dirac-Delta function. – Lucas Alanis Nov 9 '16 at 3:34
• Neat source, Jack. I didn't know something like this was so complicated. – Kaynex Nov 9 '16 at 3:37

The exponential part is irrelevant and the constant function $1$ is continuous on the interval $[-L,L]$. Hence, you can integrate its Fourier series term by term.