We can solve the heat conduction equation using implicit Euler for time and central differencing for space with Jacobi iteration as follows:
main.m1023 chars41 lines
The jacobi
function used above is a custom function that performs the Jacobi iteration. Its code is given below:
main.m117 chars5 lines
Note that we only need to solve for the interior grid points, so the first and last entries in the Tn
and b
vectors are skipped.
Also note that the forward Euler method is conditionally stable, meaning that the timestep size must be chosen carefully based on the spatial step size and diffusion coefficient to ensure stability. The Jacobi iteration is used to solve the resulting linear system at each timestep.
gistlibby LogSnag