4 An explicit numerical method for the heat equation

The approximations used above for approximating partial derivatives can now be applied in order to derive a numerical method for solving the heat conduction problem

u t = α u x x ( 0 < x < , t > 0 ) u ( 0 , t ) = 0 ( t > 0 ) u ( , t ) = 0 ( t > 0 ) u ( x , 0 ) = f ( x ) ( 0 < x < ) .

In order to specify the numerical method we choose values for δ t and δ x and use these in approximations of the two derivatives in the partial differential equation. It is convenient to divide the interval 0 < x < into equally spaced subintervals so, in effect, we choose a whole number J so that δ x = J .

Key Point 15

In order to specify the numerical procedure for solving the heat conduction equation

u t = α 2 u x 2
we need to choose δ t the time step δ x the space step

Figure 3

No alt text was set. Please request alt text from the person who provided you with this resource.

The diagram above shows the independent variables x and t at which we seek the function u . The numerical solution we shall find is a sequence of numbers which approximate u at a sequence of ( x , t ) points.

Key Point 16

The numerical approximations to u ( x , t ) that we will find will be approximations to u at ( x , t ) values where the horizontal and vertical lines cross in the above diagram (Figure 3).

The notation we use is that

u j n u ( j δ x , n δ t ) numerical exact (i.e., unknown) solution approximation evaluated at  x = j × δ x t = n × δ t

The idea is that the subscript j counts how many “steps" to the right we have taken from the origin and the superscript n counts how many time-steps (up, on the diagram) we have taken. To say this another way

No alt text was set. Please request alt text from the person who provided you with this resource.

For example, consider the point on Figure 3 which is highlighted with a small square. This point is two steps to the right of the origin (so that j = 2 ) and five steps up (so that n = 5 ). The exact solution evaluated at this point is u ( 2 δ x , 5 δ t ) and our numerical approximation to that value is u 2 5 .

Combining this new notation with the familiar idea for approximating derivatives we obtain the following approximation to the PDE

u j n + 1 u j n δ t = α u j 1 n 2 u j n + u j + 1 n ( δ x ) 2

Key Point 17

The exact solution u = u ( x , t ) satisfies the partial differential equation

u t = α u x x

The approximate (numerical) solution satisfies the difference equation

u j n + 1 u j n δ t = α u j 1 n 2 u j n + u j + 1 n ( δ x ) 2

The difference between the unknown exact solution and the numerical solution will be governed by how well the one-sided and central differences approximate the partial derivatives in the PDE.

To simplify (the appearance of) the numerical method we define a new quantity    r = α δ t ( δ x ) 2   so that our numerical procedure can be written

u j n + 1 = u j n + r ( u j 1 n 2 u j n + u j + 1 n ) = r u j 1 n + ( 1 2 r ) u j n + r u j + 1 n

This equation defines a numerical “stencil" which allows us to find one of the values at the n + 1 time level in terms of values at the previous level, n . In Figure 4 we envisage terms on the right-hand side of the above equation leading towards a result equal to the left-hand side, and the arrows therefore point towards the point at which u j n + 1 approximates u .

Figure 4

No alt text was set. Please request alt text from the person who provided you with this resource.

At the stage of the process depicted above, the solid circles represent points in the ( x , t ) plane where we have already found our numerical approximation. The unfilled circle is the point for which the new approximation u j n + 1 is being found.

4.1 Implementation

The initial condition gives u at t = 0 , and this information can be used to find

u 0 0 , u 1 0 , u 2 0 , , u J 0

that is, the numerical solution at all the selected x values and at t = 0 . In general

u j 0 = f ( j × δ x ) = f j

where f j is a shorthand notation for f ( j × δ x ) .

Then we use the boundary conditions and numerical method

u j n + 1 = u j n + r ( u j 1 n 2 u j n + u j + 1 n )

(with n = 0 ) to work out u j 1 for j = 0 , 1 , 2 , , J . (This completes the first time-step.)

The time-stepping procedure is then used repeatedly to find u j n + 1 in terms of the u j n , which are known either from the last time-step or (at the beginning) from the initial condition.

The time-stepping procedure is summarised in the following Key Point.

Key Point 18

Here the step-by-step process used to implement the numerical procedure is presented.

  1. The initial condition implies that

    u j 0 = f j ( j = 0 , 1 , 2 , , J )

    (the boundary conditions could be used to find u 0 0 and u J 0 , but our supposition is that this is consistent with taking f 0 and f J ).

  2. The first time-step



    Here we find u j 1 for j = 0 , 1 , , J .
    1. The boundary condition at x = 0 is u ( 0 , t ) = u L . It follows that u 0 1 = u L .
    2. The boundary condition at x = is u ( , t ) = u R . It follows that u J 1 = u R .
    3. Now we work from left to right finding u j 1 at the interior points. This is achieved by repeatedly applying the general numerical scheme: u 1 1 = u 1 0 + r ( u 0 0 2 u 1 0 + u 2 0 ) u 2 1 = u 2 0 + r ( u 1 0 2 u 2 0 + u 3 0 ) u J 1 1 = u J 1 0 + r ( u J 2 0 2 u J 1 0 + u J 0 )

      This completes the first time-step. We have taken the initial data and used our approximation to the PDE to obtain an approximate solution at time t = δ t .

  3. The second time-step



    Here we find u j 2 for j = 0 , 1 , , J .
    1. The boundary condition at x = 0 is u ( 0 , t ) = u L . It follows that u 0 2 = u L .
    2. The boundary condition at x = is u ( , t ) = u R . It follows that u J 2 = u R .
    3. Now we work from left to right finding u j 2 at the interior points. This is achieved by repeatedly applying the general numerical scheme: u 1 2 = u 1 1 + r ( u 0 1 2 u 1 1 + u 2 1 ) u 2 2 = u 2 1 + r ( u 1 1 2 u 2 1 + u 3 1 ) u J 1 2 = u J 1 1 + r ( u J 2 1 2 u J 1 1 + u J 1 )

      This completes the second time-step. We now have an approximation to u at time t = 2 δ t .

  4. And so on ....

The following is a concrete example of the time-stepping procedure.

Example 15

The temperature u ( x , t ) of a metal bar of length = 2 at a distance x from one end and at time t is modelled by the partial differential equation

u t = α u x x ( 0 < x < , t > 0 )

It is given that the metal has diffusivity α = 4 , that the two ends of the bar are kept at temperature u = 0 and that the initial temperature distribution is

u ( x , 0 ) = f ( x ) = x ( x )

Use the explicit difference scheme with δ x = 0.5 and δ t = 0.01 to approximate u ( x , t ) at t = δ t and t = 2 δ t .

Solution

In this case r = α δ t ( δ x ) 2 = 0.16 so that the numerical method can be written

u j n + 1 = u j n + 0.16 ( u j 1 n 2 u j n + u j + 1 n ) = 0.68 u j n + 0.16 ( u j 1 n + u j + 1 n )

We now find u j 0

u 0 0 = 0 from the left-hand boundary condition u 1 0 = f ( δ x ) = 0.75 from the initial condition u 2 0 = f ( 2 δ x ) = 1 from the initial condition u 3 0 = f ( 3 δ x ) = 0.75 from the initial condition u 4 0 = 0 from the boundary condition at the right hand end

The first time-step will find u j 1 , but first we note that u 0 1 = u 4 1 = 0 from the two boundary conditions. Now

u 1 1 = 0.68 u 1 0 + 0.16 ( u 0 0 + u 2 0 ) = 0.68 × 0.75 + 0.16 ( 0 + 1 ) = 0.670 u 2 1 = 0.68 u 2 0 + 0.16 ( u 1 0 + u 3 0 ) = 0.68 × 1 + 0.16 ( 0.75 + 0.75 ) = 0.920 u 3 1 = 0.68 u 3 0 + 0.16 ( u 2 0 + u 4 0 ) = 0.68 × 0.75 + 0.16 ( 1 + 0 ) = 0.670

The second time-step will find u j 2 , but first we note that u 0 2 = u 4 2 = 0 from the two boundary conditions. Now

u 1 2 = 0.68 u 1 1 + 0.16 ( u 0 1 + u 2 1 ) = 0.68 × 0.67 + 0.16 ( 0 + 0.92 ) = 0.603 u 2 2 = 0.68 u 2 1 + 0.16 ( u 1 1 + u 3 1 ) = 0.68 × 0.92 + 0.16 ( 0.67 + 0.67 ) = 0.84 u 3 2 = 0.68 u 3 1 + 0.16 ( u 2 1 + u 4 1 ) = 0.68 × 0.67 + 0.16 ( 0.92 + 0 ) = 0.603

(Quantities have been rounded to three decimal places here.)

Figure 5 plots the numerical solutions found in the example above. The initial condition is shown as circles. Results of the first time-step appear as squares and the second time-step is shown as stars. The line joining the values we found are not part of the numerical solution and are included only as an aid to clarity.

Figure 5

No alt text was set. Please request alt text from the person who provided you with this resource.

Notice how the numerical results are behaving as they should. The temperature decreases slightly at each time-step.

Task!

The temperature u ( x , t ) of a metal bar of length = 2 at a distance x from one end and at time t is modelled by the partial differential equation

u t = α u x x ( 0 < x < , t > 0 )

It is given that the metal has diffusivity α = 2.25 , that the two ends of the bar are kept at temperature u = 0 and that the initial temperature distribution is

u ( x , 0 ) = f ( x ) = sin ( π x )

Use the explicit difference scheme with δ x = 0.5 and δ t = 0.05 to approximate u ( x , t ) at t = δ t and t = 2 δ t .

In this case r = α δ t ( δ x ) 2 = 0.45 so that the numerical scheme can be written

u j n + 1 = u j n + 0.45 ( u j 1 n 2 u j n + u j + 1 n ) = 0.1 u j n + 0.45 ( u j 1 n + u j + 1 n )

The first stage is to use the given data to find u j 0

u 0 0 = 0 from the boundary condition u 1 0 = f ( δ x ) = f ( 0.5 ) = 0.707 from the initial condition u 2 0 = f ( 2 δ x ) = f ( 1 ) = 1 from the initial condition u 3 0 = f ( 3 δ x ) = f ( 1.5 ) = 0.707 from the initial condition u 4 0 = 0 from the boundary condition

The first time-step will find u j 1 . First we note that the boundary condition implies that u 0 1 = u 4 1 = 0 .

u 1 1 = 0.1 u 1 0 + 0.45 ( u 0 0 + u 2 0 ) = 0.1 × 0.71 + 0.45 ( 0 + 1 ) = 0.521 u 2 1 = 0.1 u 2 0 + 0.45 ( u 1 0 + u 3 0 ) = 0.1 × 1 + 0.45 ( 0.71 + 0.71 ) = 0.736 u 3 1 = 0.1 u 3 0 + 0.45 ( u 2 0 + u 4 0 ) = 0.1 × 0.71 + 0.45 ( 1 + 0 ) = 0.521

The second time-step will find u j 2 . First we note that the boundary condition implies that u 0 2 = u 4 2 = 0 . Now

u 1 2 = 0.1 u 1 1 + 0.45 ( u 0 1 + u 2 1 ) = 0.1 × 0.52 + 0.45 ( 0 + 0.74 ) = 0.383 u 2 2 = 0.1 u 2 1 + 0.45 ( u 1 1 + u 3 1 ) = 0.1 × 0.74 + 0.45 ( 0.52 + 0.52 ) = 0.542 u 3 2 = 0.1 u 3 1 + 0.45 ( u 2 1 + u 4 1 ) = 0.1 × 0.52 + 0.45 ( 0.74 + 0 ) = 0.383