NumericalSolutionoftheHeatEquation
NumericalSolutionoftheHeatEquation
Basic Properties of the Heat Equation and Its Solution. The heat
equation models heat flow in a homogeneous bar. If we assume that an
initial heat distribution on the bar is given, say u(x, t0 ), at time t0 over a
range of points x, then the physics of heat flow dictate that the temperature
at time t > t0 and point x is a function u(x, t) that satisfies ut = κuxx for
an appropriate physical constant κ which we’ve taken to be 1.
More details need to be prescribed in order to find a unique solution u.
Since the equation is first order in time and second order in space (the generic
name for the x-variable), one expects that, in addition to the one-initial con-
dition u(x, t0 ) relative to the variable t, two conditions on the space variable
need to be prescribed. The time initial condition is usually normalize to be
t = 0. For if ut (x, t) is known at a given time t, the determination of u(x, t)
by the “unraveling” of the relationship uxx = ut (x, t) requires two anti-
differentiations, or integrations, with respect to x. Since each integration
involves an arbitrary constant, there are two side, or boundary, conditions
required to recover u(x, t) from the value of ut (x, t). The boundary condi-
tions reflect physical conditions that are being assumed about the problem.
For example, requiring the temperatures at points a and b to be prescribed
values as t varies means that u(a, t) and u(b, t) are known functions. Or,
requiring the bar to be insulated at the point a means that ux (a, t) = 0 for
all t > t0 . If one considers a (bi)-infinite bar, defined for all real values of
x, then limiting conditions as |x| → ∞ or asymptotic growth conditions as
|x| → ∞ would be appropriate. Wilmott discusses all of these and more.
1
The Heat Equation c 2007 Stephen Demko
°
2
The Heat Equation c 2007 Stephen Demko
°
Numerical Methods
In our study of the numerical solution of u00 = f we saw how to discretize
the second derivative operator with central differences. The numerical so-
lution of the Heat Equation requires not only the approximation of uxx by
central differences in space, but also the discretization of the time variable.
Time discretization reduces to time stepping since we start with our initial
condition—a function, or a discretized function—and try to construct the
solution at the next time step. Equation (2) above indicates that the true
solution is really built from what one might call a “continuous time time
stepping process”. In principle one can consider creating a time stepping
method from any numerical method for the solution of ordinary differen-
tial equation of the initial value type. In practice one typically uses simple
methods whose order of accuracy is O(∆t) or, preferably, O(∆t2 ).
Discretization of Space. This follows the steps used in the notes on the
DISCRETE SECOND DERIVATIVE MATRIX with the exception that our
function u is now a function of both x and t. We discretize in x while keeping
the t continuous.
If u(x, t) is a sufficiently differentiable function, then the standard central
difference approximation to uxx (x, t) is
1
uxx (x, t) = [u(x + h, t) − 2u(x, t) + u(x − h, t)] + O(h2 )
h2
We can approximate the second space derivative of u on a space interval
[a, b], for arbitrary t, as follows:
(1) divide [a, b] into N intervals of equal length by the equally spaced
partition points xi :
a = x0 < x1 < . . . xN = b
where xi − xi−1 = (b − a)/N = h. With this we have the formulas for
1≤i≤N −1
1
uxx (xi , t) = [u(xi+1,t ) − 2u(xi , t) + u(xi−1 , t)] + O(h2 )
h2
3
The Heat Equation c 2007 Stephen Demko
°
If u(a, t) = L(t) and u(b, t) = R(t), then the global relationship expressed
by the equations above can be written in matrix form as
2 3 2 3 2 u(x1 , t) 3 2 3
uxx (x1 , t) −2 1 0 0 ... 0 L(t)
6 uxx (x2 , t) 7 6 1 −2 1 0 ... 07 6 u(x2 , t) 7 6 0 7
6 7 6 76 7 6 7
6 .. 7 6 0 1 −2 1 ... 07 6 .. 7 6 .. 7
6 . 7 6 76 . 7 6 . 7
6 7 = 1 6 7+ 1 6 7
6 . 7 h2 6 .
6 .. .. .. .. .. .. 7 6
7 . 7 h2 6 . 7+
6 .. 7 6 . . . . . 76 .. 7 6 .. 7
6 7 40 6 7 6 7
4u (x 5 0 ... 1 −2 1 5 4u(x 5 4 0 5
xx N −2 , t) N −2 , t)
uxx (xN −1 , t) 0 0 ... 0 1 −2 u(x , t) R(t)
N −1
O(h2 )
where the O(h2 ) quantity is the error vector whose contents are unknown,
but whose magnitude is known to be of order h2 as h → 0. This error vector
also depends on t.
Let’s write the above system as uxx = h12 Au + h12 b + O(h2 ).
From this we can see that the Heat Equation ut = uxx with initial con-
dition u(x, t0 ) = u0 (x) and boundary conditions u(a, t) = L and u(b, t) = R
becomes the (N − 1) × (N − 1) system of coupled ordinary differential equa-
tions:
u(x , t)
ut (x1 , t) −2 1 0 0 ... 0 1 L(t)
ut (x2 , t) 1 u(x2 , t) 0
−2 1 0 ... 0
.. 0 .. ..
. 1 −2 1 ... 0 . .
= 1
.. .. .. .. .. .. + 1
. h2 . . h2 .
.. . . . . . .
. ..
0
ut (xN −2 , t) 0 ... 1 −2 1 u(xN −2 , t) 0
ut (xN −1 , t) 0 0 ... 0 1 −2 u(xN −1 , t) R(t)
Since x has been discretized, and our only continuous variable is t, we
write this system as
1
(5) u0 (t) = Ah u(t) + b(t)
h2
In this equation
−2 1 0 0 ... 0
1 −2 1 0 ... 0
1 0 1 −2 1 ... 0
Ah = 2 .. . . .. .. .. ..
h . . . . . .
0 0 . . . 1 −2 1
0 0 ... 0 1 −2
the time steps follow. For simplicity, we define the matrix R = (I + ∆tAh )
and observe:.
∆t
(7) um+1 = Rum + bm
h2
∆t
(8) = R2 um−1 + 2 (Rbm + bm−1 )
h
Xm
∆t
(9) = Rm+1 u0 + 2 ( Rj bj )
h
j=0
We can assume that the vectors bj are well behaved and that the process
of summing does not lead to instabilities. The issue that has to be explored
for stability analysis is the growth of the powers of R. As we have noted
above in the case of the Explicit Euler Method, the matrix is simply I +
∆tAh . The stability of this matrix is analyzed in a later section.
Implicit Euler Method. Here we use the same Taylor-based approxima-
tion to ut , but match it with Ah u1 :
∆t
u1 = u0 + ∆tAh u1 + 2 b1
h
so u1 is determined as the solution of a linear system
∆t
u1 − ∆tAh u1 = u0 + 2 b1
h
m
Therefore, the step from u to u m+1 requires the solution of the linear
system
∆t
(10) T um+1 = um + 2 bm+1
h
where T = (I − ∆tAh ) is a real, tridiagonal, positive definite, symmetric
matrix. As such it has a Cholesky decomposition T = CC T where C is
lower triangular bi-diagonal matrix, that is C has the form:
d1 0 . . . . . . 0
..
l2 d2 0 . 0
.. ..
C= 0 l 3 d3 .
.
. .
.. .. ... ..
. 0
0 ... 0 lN −1 dN −1
The Cholesky Decomposition permits us to replace the general system
Tu = f
with the two easily solved systems
(11) Cy = f
(12) CT u = y
6
The Heat Equation c 2007 Stephen Demko
°
Here’s a quick proof that the vector u obtained by solving systems (11)
and (12) solves the original system: T u = CC T u = C(C T u) = Cy = f .
It is important to note that the Cholesky Decomposition is computed one
time only and the vectors um for m ≥ 1 are calculated by
(1) The algorithm given for solution is very fast partly because by virtue
of the one time factorization many of the steps of Gaussian elimina-
tion needed to be carried out one time only.
(2) the Implicit Method is always stable while the Explicit Method has
stability “issues”
Crank-Nicolson Method. The idea here is to average the Implicit and
Explicit methods. First, we review the scalar case. For the equation
y 0 (t) = f (x, y)
the Explicit and Implicit Euler methods are given by the formulas:
yn+1 = yn + ∆tf (xn , yn )
yn+1 = yn + ∆tf (xn+1 , yn+1 )
BDF2. The stability analysis in this case is more subtle because of the two-
step nature of the method. First we represent the two initial vectors u0 and
u1 in terms of the eigenvectors of A, say
(16) u0 = a1 v1 + a2 v2 + · · · + an vn
(17) u1 = b1 v1 + b2 v2 + · · · + bn vn
Then, we can show that the coefficient of vi in the representation of un+1
in terms of these eigenvectors satisfies (we are not showing the dependence
of the coordinate on i):
4 1
(18) cn+1 = cn − cn−1
3 − 2αλi 3 − 2αλi
That is, the eigenvector coordinates each satisfy a three-term recurrence
relation in which the eigenvalue for that eigenvector plays a role.
We analyze the behavior of the cn ’s with the same method we used to
analyze stability of the ODE solvers based on quadratic interpolation. From
equation (18) we derive the quadratic equation:
(19) (3 − 2αλ)r2 − 4r + 1 = 0
where −4 < λ < 0 and α > 0. Things get a bit simpler if we set γ = −2αλ
and note that the only constraint on γ is that it be positive. The quadratic
formula gives:
p √
4 ± 16 − 4(3 + γ) 2 ± 1 − 4γ
(20) r= =
2(3 + γ) 3+γ
There are two cases to consider:(1) 0 < γ ≤ 14 , in which case the roots
are real and (2) γ > 14 in which case the roots are complex.
√ √
Case 1: There are 2 roots: r+ (γ) = 2+3+γ1−4γ
and r− (γ) = 2−3+γ1−4γ
. For
2
r+ we have r+ (0) = 1, r+ (0.25) = 3.25 < 1, and r+ is decreasing between
0 and 0.25. For r− we have r− (0) = 23 , r− (0.25) = 3.25 2
< 1, and r− is
increasing between 0 and 0.25. We note that the value of 1 obtained in the
case that γ = 0 cannot be attained in practice since γ is neither α (the ratio
of time step to space step) nor λ (eigenvalue of A) is ever 0.
10
The Heat Equation c 2007 Stephen Demko
°
q
4+(4γ−1)
Case 2: There are 2 complex roots, each of magnitude (3+γ)2
For
q
γ = 0 this expression equals 13 , for γ > 0 the expression decreases mono-
tonically to 0.
Finally, we note that the highly oscillatory eigenvectors of A, those that
correspond to eigenvalues of A close to −4. If we chose ∆t ≈ h, so that
α = h∆2 ≈ h1 ≈ N where N is the dimension of the matrix, we have γ ≈
8N . So we are usually in the regime of Case 2, so that all frequencies, in
particular the highly
q oscillatory ones, are damped quickly: each step reduces
1
the magnitude by 3.
12