Solution (source code)

= Solution

Apply <separation of variables> with $\rho(x,t)=X(x)T(t)$ and temporal factor $T=e^{-\lambda t}$. The spatial <eigenvalue> equation is
$$
-DX''-\gamma X=\lambda X,\qquad X(0)=X(L)=0.
$$
The nontrivial solutions of these <Dirichlet boundary conditions> are sine <eigenfunctions>. Normalizing in the usual <inner product> on $(0,L)$ gives
$$
\boxed{\psi_n(x)=\sqrt{\frac2L}\sin\frac{n\pi x}{L},\qquad\lambda_n=D\left(\frac{n\pi}{L}\right)^2-\gamma,\qquad n=1,2,\ldots,}
$$
with $\int_0^L\psi_n\psi_m\,dx=\delta_{nm}$. The <superposition principle> and the <Fourier sine series> then give
$$
\boxed{\rho(x,t)=\sum_{n=1}^{\infty}a_n\sqrt{\frac2L}\sin\frac{n\pi x}{L}\exp\left[\left(\gamma-\frac{Dn^2\pi^2}{L^2}\right)t\right].}
$$
The constants are the initial-data coefficients $a_n=\int_0^L\rho(x,0)\psi_n(x)\,dx$. Here physical diffusion means $D>0$.