Solution (source code)

= Solution

For a nonzero separated solution $U=X(x)T(t)$, <separation of variables> gives $X''/X=T'/T=-\lambda$. The zero <Dirichlet boundary conditions> <force> $X=\sin nx$, $\lambda=n^2$, with <integers> $n\geq1$; the time factors are $e^{-n^2t}$. Expanding the initial profile in this <Fourier sine series> requires only the two already displayed spatial modes. Thus
$$
\boxed{U(x,t)=3e^{-t}\sin x-e^{-9t}\sin3x.}
$$
Both terms individually solve the <heat equation>, vanish at the endpoints and give the required initial profile at $t=0$. The initial function is also $4\sin^3x\geq0$ on the bar; the later solution stays nonnegative and tends to zero as <heat> leaves through the fixed-temperature ends.