Here's a possible implementation:
main.m1077 chars56 lines
This code uses the implicit Euler method in time and central differencing in space to solve a 2D heat equation with constant thermal diffusivity alpha
. The time loop contains a Jacobi solver that iteratively updates the temperature T
until it converges to the new solution. The discretized unknowns are T(i,j)
at the grid points (i,j)
, and the coefficients ae, aw, an, as, ap
depend on the grid spacing and the thermal diffusivity.
To plot the temperature at particular times, the code checks if the current time step n
is in a predefined list, and if so, it creates a new figure with an image plot of the temperature using imagesc(T')
(note the transpose, which makes the plot have the same orientation as the plate). The plot is labeled with the current time n*dt
and other relevant information. The axis equal tight
command is used to make the plot square and remove any extra margins.
gistlibby LogSnag