To plot the contour of the temperature on the 2D plate at specific times with the discretised PDE using Jacobi's solver, Implicit Euler for time and central differencing for space in MATLAB, we assume a rectangular plate over the domain (xmin, xmax)= (0,1) and (ymin, ymax)= (0,1) with N discretisation points for both x and y. We have to solve the heat diffusion equation in 2-D in the form:
The initial condition of the above heat diffusion equation is given by:
The boundary conditions for the above equation are:
Here, we use Jacobi Iterations to solve the diffusion equation at each time step. Given the Jacobi's method to numerically solve this problem, we only pass pointers as Jacobi's function input. A function jacobi
is used to compute Jacobi's method with implicit Euler for time, central differences for space.
After getting the temperature matrix (T) at different times, we create the contour plots using the matlab function contourf
.
Here's the MATLAB code for the above simulation.
main.m1171 chars57 lines
Here, we first initialise the constants N, tmax, dt, dx, dy and k with discretisation and thermal properties of the plate.
Next, we define the initial temperature on the 2D plate at t=0, with certain boundary conditions. The grid formation of the plate is done with the meshgrid
function.
Afterward, we loop over time t
from 0
to tmax
with step size dt
.
Inside the time loop, we copy the old temperature array T_old to new temperature array T_new for later comparison.
Then, we perform Jacobi Iterations to numerically compute the temperature at each time step. The loop continues until the convergence criterion has been reached, in this case, after 500
iterations.
Finally, we update the T_old with T_new computed and at specific time points, create the contour plots of temperature using the MATLAB contourf
function.
Note that the pause(0.1)
function at the end of the contour plot inside the for loop is put to slow down the iteration and animation for visualization purposes.
Also, don't forget to define the Jacobi Iterations function.
main.m668 chars30 lines
The above jacobi
function computes Jacobi's method with implicit Euler for time, central differences for space. It takes Tp = temperature matrix array, Tpo = temperature matrix array as input and solves for the solution matrix Tp while updating the input Tp array at each iteration.
Overall, this piece of code gives us the contour plot of temperature at several time steps.
gistlibby LogSnag