Solution (source code)

= Solution

The line references below use the original listing's line numbers.

* Lines 1–7 set the grid dimensions, domain lengths, <thermal diffusivity> and time interval. The elapsed time is $n_t\Delta t=10\,\mathrm s$.
* Lines 9–10 supply coordinates, subject to the periodic-grid correction above. Lines 16–17 sample the initial <Gaussian function>.
* Lines 11–14 construct the <discrete Fourier transform> frequency order and $K^2=K_X^2+K_Y^2$. Negative frequencies occupy the second half of each array. This is the discrete version of replacing each spatial derivative by multiplication by $ik$.
* Line 20 computes the two-dimensional <Fast Fourier transform>. Lines 22–24 multiply every mode by $\exp(-\alpha K^2\Delta t)$ at every step, implementing the modal solution derived above.
* Line 26 performs the inverse <discrete Fourier transform>. Taking the real part removes tiny imaginary <roundoff errors>; conjugate symmetry of the exact transformed real data already guarantees a real result.
* Lines 28–42 display the initial and final arrays. A common colour scale is needed to compare their peak <temperatures>; independent automatic colour scales can hide the decrease in amplitude.

For this linear homogeneous problem, the exponential update is exact for the retained modes, apart from <roundoff error>. It is not a forward <Euler method> step and does not require the explicit finite-difference diffusion stability restriction. Sampling, periodic modelling and spatial resolution still matter.