Solution (source code)

= Solution

Use $N$ distinct periodic grid points $x_m=m/N$, $0\leq m<N$, and $h=1/N$. Values at the two ends of the interval represent the same point, so the endpoint must not be stored twice. With indices interpreted modulo $N$, set
$$
\boxed{(1+2\mu)U_m^{n+1}
-\mu(U_{m-1}^{n+1}+U_{m+1}^{n+1})=U_m^n.}
$$
This replaces the Dirichlet matrix by the periodic discrete Laplacian. The normalized <Fourier modes> $N^{-1/2}e^{2\pi ijm/N}$ form an <orthonormal basis> and have amplification factors
$$
\boxed{g_j=\frac1{1+4\mu\sin^2(\pi j/N)},\qquad 0\leq j<N.}
$$
Each satisfies $0<g_j\leq1$ for every $\mu>0$. The <Parseval identity> therefore gives $\|U^{n+1}\|_h\leq\|U^n\|_h$ in the <discrete L2 norm>, uniformly in the grid and time step. Thus \b[all positive <Courant numbers> remain stable]. The constant mode has $g_0=1$, expressing preservation of the spatial mean; all nonconstant modes decay. The formula with modulo indices also handles small grids, where two neighbours can coincide.