= Solution
A spatially uniform source changes only the <zero Fourier mode>. Its exact integrated increment over a time step beginning at $t$ is
$$
\Delta q=\int_t^{t+\Delta t}0.1e^{-s/10}\,ds
=e^{-t/10}-e^{-(t+\Delta t)/10}.
$$
The unnormalised two-dimensional <discrete Fourier transform> stores a constant field $q$ as $n_xn_yq$ in element `(1,1)`.<fft2 documentation by MathWorks>[The forward defining sum has no normalization; the linked inverse definition includes the factor $1/(n_xn_y)$.]{ref} Keep the existing homogeneous exponential multiplication and add this source increment to that element:
``
for i = 1:nt
t = (i-1)*dt;
u_hat = u_hat .* exp(-alpha*K2*dt);
dq = exp(-t/10) - exp(-(t+dt)/10);
u_hat(1,1) = u_hat(1,1) + nx*ny*dq;
end
``
This replacement uses the original variable names and <MATLAB> indexing. The <uniform forcing of a periodic heat equation> is integrated exactly in time here. No source multiplier is applied to the other modes, and the zero-mode homogeneous multiplier equals one. Adding only `dq` to the unnormalised coefficient would underestimate the physical temperature increment by the factor $n_xn_y$.
Back to article page