I need to solve the diffusion equation using a Fourier Series. The PDE is
$$ \frac{\partial \rho (x,t)}{\partial t} = D\frac{\partial ^2 \rho (x,t)}{\partial x^2} $$
The initial and boundary conditions are the following
$$ \rho (0,t)=\rho (L_x,t) = 0 $$ $$ \rho (x,0) = A e^{ - \frac{(x-x_0)^2}{l}} $$
where $D, L_x, A, x_0$ and $l$ are given constants.
I need help to see if what I did to solve it is correct. I separated the equation: $\rho(x,t)=X(x)T(t)$, then divided the equation by $DX(x)T(t)$ and finally made it equal to $-k^2$.
After applying the boundary conditions and the initial condition, I got the following Fourier Series:
$$ \rho (x,t) =A \sum_{n=1}^{\infty} a_n \sin {\left(\frac{n\pi}{L_x}x \right)}\exp{\left( -D \left(\frac{n\pi}{L_x} \right)^2 t - \frac{(x-x_0)^2}{l} \right)} $$
Now, I honestly don't know how to get an expression for the $a_n$. I think I have to integrate it from $0$ to $L$ but this seems more complicated than what it should be so I need to make sure that I have the Fourier Series correct.