Interactive Educational Modules in
Scientific Computing

Heat Equation

This module illustrates fully discrete finite difference methods for numerically solving the heat equation. The heat equation (also called the diffusion equation) in one space dimension is the partial differential equation ut = c uxx, where the solution u(t, x) is a function of the time variable t and the spatial variable x, and subscripts indicate partial differentiation with respect to the given independent variable. The equation is defined for any x in a given interval [a, b] and any nonnegative t. The initial condition is given by u(0, x) = f(x) for some specified function f, and boundary conditions are given by u(t, a) = α and u(t, b) = β for specified values α and β. Here we take c = 1, α = 0, and β = 0 for simplicity.

The user begins by selecting an initial function from the menu provided. The initial function, represented by a truncated Fourier sine series approximation, is plotted on a predetermined interval [a, b] for which u(0, a) = u(0, b) = 0. Next, the user chooses a fully discrete finite difference method to apply to the heat equation. The stencil of the method is shown below the list of methods, with the point being computed colored red, the points it depends on colored blue, and the remaining points colored black. Finally, the user specifies the step sizes in space and time for the discrete mesh of points used in the finite difference method. The stability limit shown below gives, for the chosen space step size, the restriction on the size of the time step in order for the numerical method to be stable. If the time step chosen violates this restriction, then the numerical solution may oscillate wildly and bear little resemblance to the true solution.

To view the numerical solution, the user chooses between two-dimensional and three-dimensional display modes and then clicks Start. The approximate solution is advanced time step by time step, and the plot of the solution is updated accordingly. In two-dimensional display mode, the solution at the current time is plotted as a curve on the spatial interval [a, b], and solution values at each new time step replace those at the previous time step. The approximate solution is shown in green, and the exact solution is shown in red for comparison. In three-dimensional display mode, the approximate solution is plotted as a surface over the space-time plane, and solution values at each new time step are added to the existing graph, extending it forward along the time axis. The solution continues to advance until a fixed upper limit is reached or the user clicks Stop. When the solution process is stopped before reaching the final time, it can be resumed by again clicking Start. Clicking Reset halts any solution that may be in progress and redisplays the initial condition, allowing the user to select a different initial condition, a different solution method, or different step sizes.

Reference: Michael T. Heath, Scientific Computing, An Introductory Survey, 2nd edition, McGraw-Hill, New York, 2002. See Section 11.2.2, especially Example 11.2 and Figure 11.5.

Developers: Evan VanderZee and Michael Heath