# The Two-Dimensional Heat Equation

## Physical and Mathematical Background

Consider a flat thin plate which we divide into a grid of NxN cells. Let u[i,j] denote the temperature of the cell in position (i,j). Thus, if N = 5 and if i and j run from 0 to 4, we could have a temperature distribution like this:
0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00
1.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00
This represents a temperature distribution where the cell in the second row and zeroth column is hot (at temperature 1) and the remaining cells are cold (at temperature 0). We write this fact as u[2,0] = 1, u[i,j] = 0 for [i,j] different from [2,0].

What is the temperatue u at future times, given that (a) the temperatures are held fixed at the edges of the plate and (b) the rest of the plate is well insulated? The physics governing temperature in a thin plate is the same as that governing temperature in a thin rod:

The rate of change of the temperature at a given point is proportional to the difference between the average temperature near the point and the temperature at the point.
Let us see how this applies to our model, in which we have divided the rod into finitely many cells each of which has a unique temperature. This is, of course an approximation, since the temperature in a cell will in fact vary. However, if the cell is small, the approximation will be a good one. Now, assuming that u[i,j] is the temperature of the cell in position (i,j) at time t, let uu[i,j] denote the temperature of the cell in position (i,j) at time t + h, where h is small. Then our principle reads
uu[i,j] = u[i,j] + k(( u[i-1,j] + u[i+1,j] + u[i,j-1] + u[i,j+1] )/4 - u[i] )
for i = 1..N-2, j = 1..N-2
Here k is the constant of proportionality. Note that when k = 1, this is particularly simple:
uu[i] = ( u[i-1,j] + u[i+1,j] + u[i,j-1] + u[i,j+1] )/4
for i = 1..N-2, j = N-2

It is not difficult to write a program which computes and displays the future temperatures of a thin, insulated rod given a temperature distribution at time t = 0. The outline is the same as in the case of the long thin rod:

PSEUDOPROGRAM:

Constants: N, the number of cells in a row or column
T, the number of time steps

Variables: u, an array which holds the current temperature distribution
uu, an array which holds the "next" temperature distribution

Program:

Set up the array u;
Print it out;

For t from 1 to T:
Compute uu from u
Print out uu
Copy uu into u

Here is a more detailed outline of the program, written in pseudo-C:

#define N 5  /* number of cells in a row or column */
#define T 5  /* number of time steps */

main()
{

/* Note that in C we refer to the temperature of the
cell in position (i,j) as u[i][j].
*/

double u[N][N], uu[N][N];  /* temperature arrays */
int i,j,t;

/* initialize u */
for( i=0; i < N; i++ )
for( j=0; j < N; j++ )
u[i][j] = 0;

u[2][0] = 10;

/* Note the use of a double loop to process the array.
The index i controls the cell row and the index j
controls the cell column.  This is the model
you should use in converting the pseudoprogram
to a program.
*/

/* display u */
printf("\n  t = 0: \n\n");
for( i=0; i < N; i++ ){
for( j= 0; j < N; j++ )
printf("%5.2f", u[i][j] );
printf("\n");
}
printf("\n");

/* Compute and display future temperatures */
for( t=1; t < T; t++ ) {
/* carry forward boundary temperatures */
/* compute interior temperatures */
/* display temperature at time t */
/* update u */
}

## Problems

1. Let k = 1. Find uu from u using the initial data given above. Do this by hand.
2. Write a program based which computes and displays the future temperatures at times t = 1..N given an initial temperature distribution. Use the pseudoprogram given above as an outline, and use the given initial data. Run your program for through time t = 10. Report all the data, and find the temperature in the middle cell at time t = 10.
3. Discuss the limiting behavior of the temperature distribution: what is it for t very, very large, and what is its limit as T goes to infinity?
4. Find the temperature distribution on an 11x11 grid at time t = 10 where all initial temperatures are zero except u[5,0] = 100. What is the temperature of the center cell at t = 10?

Back to syllabus
Back to Department of Mathematics, University of Utah
Created Feb 28, 1995