# Chapter 4

FD methods for linear parabolic
PDE

A linear PDE of the form

ut = Lu, (4.1)

where t usually denotes the time and L is a linear elliptic diﬀerential operator in one or
more spatial variables, is called parabolic. Furthermore, the second order canonical form

a(x, t)utt + 2b(x, t)uxt + c(x, t)uxx + lower order terms = f (x, t)

is parabolic if b2 − ac ≡ 0 in the entire x-t domain. Note that, we can transform this second
order PDE into a system of two PDEs by setting v = ut , where the t-derivative is ﬁrst
order. Some important parabolic PDE are as follows.

• 1D heat equation with a source

ut = uxx + f (x, t).

The dimension refers to the space variable (x direction).

• General heat equation

ut = ∇ · (β∇u) + f (x, t) , (4.2)

where β is the diﬀusion coeﬃcient and f (x, t) is the source (or sink) term.

ut = ∇ · (β∇u) + w · ∇u + f (x, t) ,

where ∇ · (β∇u) is the diﬀusion term and w · ∇u the advection term.

61

Some commonly used FD methods We discuss the following FD methods for parabolic PDE in this chapter: • the forward and backward Euler methods.. 0) = u0 (x) for the above PDE. 0) = 0 then limt→∞ u(x. The steady state solutions (when ut = 0) are the solutions of the corresponding elliptic PDEs. it can of course be rendered at t = 0 by a translation t = t − T .62 Z. t. if a Dirichlet boundary condition is prescribed at x = a and x = b such that u(a. we only consider the numerical solution of dynamically stable problems. t) = g2 (t). and . t)| ≤ C.e. If the initial condition is given at t = T = 0.. The nonlinear source term f (x. • the Crank-Nicolson and θ methods. Note that the boundary conditions at t = 0 may or may not be consistent with the initial condition. u).e. Dynamical stability 2 √ The fundamental solution u(x. Some applications are dynamically unstable and “blow up”. i. u) = f¯(x. but we do not discuss how to solve such dynamically unstable problems in this book. provided a good ODE solver can be applied. if there is no constant C > 0 such that |u(x.. Li • Canonical form of diﬀusion-reaction equation ut = ∇ · (β∇u) + f (x. t) = g1 (t) and u(b. we expect to have an initial condition at t = 0 in addition to boundary conditions at x = a and x = b say. t) = ∞. for the backward heat equation ut = −uxx . However.g. The solution is said to be dynamically unstable if it is not uniformly bounded. if u(x. u) = 0 for the last case. in addition to relevant boundary conditions. e. t. Thus for the 1D heat equation ut = uxx on a < x < b for example.. there is an initial condition that is usually speciﬁed at t = 0 i. u) is the reaction.e. u) exists. i. assuming lim f (x. u(x.t) = e−x /4t / 4πt for the 1D heat equation ut = uxx is uniformly bounded. t→∞ Initial and boundary conditions In time-dependent problems. t. • the method of lines (MOL). then u0 (a) = g1 (0) and u0 (b) = g2 (0) for consistency.. i. ∇ · (β∇u) + f¯(x.e.

. · · · . ut = βuxx + f (x. u(x. MOL \tex{MOL} BC \tex{BC} BC \tex{BC} k+1 \tex{\$k+1\$} k \tex{\$k\$} FW-CT \tex{FW−CT} BW-CT \tex{BW−CT} t=0 \tex{\$t=0\$} IC \tex{IC} Figure 4. t) = g2 (t). · · · . k = 0. i = 0. t) = g1 (t). m T tk = kΔt. Δt = n It turns out that any arbitrary Δt cannot be used for explicit methods because of numerical instability concerns. To consider the stability of the consequent numerical methods. h= . for high-dimensional problems. u(b. t > 0. 1.1 The Euler method For the following problem involving the heat equation with a source term. let us seek a numerical solution for u(x. and the method of lines (MOL). t). let us focus on possible FD formulas for the time derivative. t) at a particular time T > 0 or at certain times in the interval 0 < t < T . 1. m. As the ﬁrst step. so let us focus on the time discretization and initial condition(s).1: Diagram of the FD stencil for the forward and backward Euler methods. we expect to generate a grid b−a xi = a + ih. . we invoke a Fourier trans- formation and von Neumann stability analysis. 0) = u0 (x) . n . a < x < b. 4. Since we already know how to discretize the spatial derivatives.FD methods for linear parabolic PDE 63 • the alternating directional implicit (ADI) method. u(a. FD methods applicable to elliptic PDE can be used to treat the spatial discretization and boundary conditions. The second step is to approximate the derivatives with FD approxi- mations.

i = 1. t) T (x. t) − 2u(x. . In passing. we note an alternative deﬁnition of the truncation error in the literature   u(x − h. t) Δt h2 = O(h2 + Δt) .2) h2 The solution of the FD equations is thereby directly obtained from the approximate solution at previous time steps and we do not need to solve a system of algebraic equations. t) = −β − f (x. tk ) + T (xi . tk ) − 2u(xi . (4. t) + u(x + h. t) u(x − h. on using the forward FD approximation for ut and central FD approximation for uxx we have u(xi . tk ) + utt (xi . t) h2   = O Δt(h2 + Δt) introduces an additional factor Δt. 0). tk ). k > 0. tk ) + · · · . tk ). so the method is called explicit. t + Δt) − u(x. The local truncation error is h2 β Δt T (xi . and then at t2 using the approximate solution at t1 . t) = u(x. t) + u(x + h. and from the values Uik at the time level k the solution of the FD equation at the next time level k + 1 is   k − 2U k + U k Ui−1 k+1 k i i+1 k Ui = Ui + Δt β + fi . 2. tk ) =β Δt h2 + f (xi . when the FD equation is Uik+1 − Uik U k − 2Uik + Ui+1 k = β i−1 + fik (4. 12 2 where the dots denote higher order terms.1 Forward Euler method (FT-CT) At a grid point (xi . When k = 0. · · · . tk ) . Indeed. Li 4. so the discretization is O(h2 + Δt). t + Δt) − u(x. Ui0 is the initial condition at the grid point (xi . tk + Δt) − u(xi .1) Δt h2 where fik = f (xi . tk ) u(xi−1 . The dis- cretization is ﬁrst order in time and second order in space. m − 1 . Remark 4.1 The local truncation error under our deﬁnition is u(x. t) − Δt β − f (x. with Uik again denoting the approximate values for the true solution u(xi . we successively compute the solution at t1 from the initial condition at t0 . tk ) = uxxxx (xi . so it is one order higher in Δt. Such an approach is often called a time marching method. t) T (x. t) − 2u(x. tk ) + u(xi+1 .64 Z. tk ).1.

Since the method is consistent. the local truncation error is   β 2 Δt βh2   T (x. we cannot get Uik+1 with a few simple algebraic operations because all of the Uik+1 ’s are coupled together.1. often called the CFL (Courant-Friedrichs-Lewy) stability condition. tk ). to prevent the errors in uki being ampliﬁed. Using the backward Euler method. one can set 2βΔt h2 ≤1. in order to get the approximate solution at the . we get Uik − Uik−1 U k − 2Uik + Ui+1 k = β i−1 + fik . (4.. (4.4) h2 2β This is a time step constraint. we ﬁnd the method works for some values of Δt but blows up for some others.3) 2 12 Thus if β is constant we can choose Δt = h2 /(6β) to get O(h4 + (Δt)2 ) = O(h4 ). we anticipate that this is a question of numerical stability. i.2 If f (x. k = 0. Δt h2 which is conventionally re-expressed as Uik+1 − Uik U k+1 − 2Uik+1 + Ui+1 k+1 = β i−1 + fik+1 . or Δt ≤ . Intuitively. Thus we need to solve the following tridiagonal system of equations. which is signiﬁcant for an explicit method. 4. · · · .5) Δt h2 The backward Euler method is also consistent. k = 1. 2. On testing the forward Euler method with diﬀerent Δt and checking the error in a problem with a known exact solution. · · · .FD methods for linear parabolic PDE 65 Remark 4. then from ut = βuxx and utt = β∂uxx /∂t = β∂ 2 ut /∂x2 = β 2 uxxxx .e. t) ≡ 0 and β is a constant. (4. and the discretization error is again O(Δt + h2 ).2 The backward Euler method (BW-CT) If the backward FD formula is used for ut and the central FD approximation for uxx at (xi . the local truncation error is fourth order accurate without further computational complexity. t) = − uxxxx + O (Δt)2 + h4 . 1.

. ⎥ ⎢ . The advantage of the backward Euler method is that it is stable for any choice of Δt.66 Z. we can use the ODE Suite to solve a system of ordinary diﬀerential equations.. because the solution at time level k + 1 are coupled together. ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ k+1 ⎥ ⎢ −μ 1 + 2μ −μ ⎥ ⎢ Um−2 ⎥ ⎣ ⎦⎣ ⎦ k+1 −μ 1 + 2μ Um−1 ⎡ ⎤ (4. ode15s. Such a numerical method is called an implicit. t) . ode45 and others. . t) + f (x. we can use the method of lines (MOL) to solve parabolic partial diﬀerential equations.6) U1k + Δt f1k+1 + μg1k+1 ⎢ ⎥ ⎢ k k+1 ⎥ ⎢ U2 + Δt f2 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ k U3 + Δt f3 k+1 ⎥ ⎢ ⎥ =⎢ ⎢ ⎥. Note that we can use f (xi . ⎥⎢ . ⎥ ⎢ .. Li time level k + 1: ⎡ ⎤⎡ ⎤ 1 + 2μ −μ U1k+1 ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ k+1 ⎥ ⎢ −μ 1 + 2μ −μ ⎥ ⎢ U2 ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ k+1 ⎥ ⎢ −μ 1 + 2μ −μ ⎥⎢ U ⎥ ⎢ ⎥⎢ 3 ⎥ ⎢ ⎥⎢ ⎥ ⎢ .. Consider a general parabolic equation of the form ut (x. [?]. ⎥ ⎢ ⎥ ⎢ k k+1 ⎥ ⎢ Um−2 + Δtfm−2 ⎥ ⎣ ⎦ k k+1 k+1 Um−1 + Δt fm−1 + μg2 where μ = βΔth2 and fik+1 = f (xi . The Matlab function ode23 uses a combination of Runge-Kutta methods of order 2 and 3 and uses an adaptive time step size. the computational cost is only slightly more than the explicit Euler method if we can use an eﬃcient tridiagonal solver. Let Lh be a corresponding FD operator acting on a grid . Ref. cf.2 The method of lines (MOL) With a good solver for ODE or systems of ODE. In Matlab. For 1D problems. . ⎥ ⎢ . such as the Grout factorization method at cost O(5n). ode23s. tk+1 ). tk ) instead of f (xi .. t) = Lu(x.. where L is an elliptic operator. for example. . tk+1 ). ⎥ ⎢ . The ODE Suite contains Matlab functions such as ode23. since the method is ﬁrst order accurate in time. The Matlab function ode23s is designed for a stiﬀ system of ODE. 4.

e. ∂t h2 h and the initial condition is Ui (0) = u0 (xi . we typically have dy = Ay + c .e. (4. t) along the line x = xi . ysol = y(mr. y0). [0. dt where A is a matrix and c is a vector. i = 2. However. t_final]. Both A and c may depend on t.1) ∂t h2 ∂Um−1 (t) Um−2 (t) − 2Ui−1 (t) g2 (t) = β + 2 + f (xm−1 .2) The ODE system can be written in the vector form dy = f (y.m whose contents contain the following . To deﬁne the ODE system of the MOL.:). (4. ∂t where Ui (t)  u(xi .. for the heat equation the magnitude of the eigenvalues range from O(1) to O(1/h2 ). it is important to recognise that the ODE system ob- tained from the MOL is typically stiﬀ. Most are based on high order Runge-Kutta methods with adaptive time steps. t). (4.. There are many eﬃcient solvers for a system of ODE. i = 1. which can be extracted using [mr. u. m − 2 . We can form a semi-discrete system of ordinary diﬀerential equations of form ∂Ui = Lh Ui (t) + fi (t) . t). Then ysol is the approximate solution at time t = t f inal. In Matlab. e. t) .3) dt The MOL is especially useful for nonlinear PDE of the form ut = f (∂/∂x. we can create a Matlab ﬁle. 2. ODE suite in Matlab. say yfun-mol. For example. y(0) = y0 .FD methods for linear parabolic PDE 67 xi = a + ih.f available through Netlib. i. we can call an ODE solver using the format [t. m − 1 . ∂t h2 h ∂Ui (t) Ui−1 (t) − 2U2 (t) + Ui+1 (t) = β + f (xi .nc] = size(y). · · · . t) ..g. i. the heat equation with a source ut = βuxx + f where L = β∂ 2 /∂x2 is represented by Lh = βδxx 2 produces the discretized system of ODE ∂U1 (t) −2U1 (t) + U2 (t) g1 (t) = β + 2 + f (x1 . t).y] = ode23s(’yfun-mol’. 3. For example. 0). or dsode. the eigenvalues of A have very diﬀerent scales. The solution is stored in the last row of y. · · · . we only discretize the spatial variable. t) is the spatial discretization of u(x. For linear problems.

(4. The Crank-Nicolson scheme is based on the following lemma. which can be proved easily using the Taylor expansion.68 Z. end where u0 (x) is a Matlab function of the initial condition. The initial condition can be deﬁned as global m h x for i=1:m-1 y0(i) = u_0(x(i)). One FD scheme that is second order accurate both in space and time.x(i)). The backward Euler method does not have the time step constraint. the Crank-Nicolson scheme approximates the PDE ut = (βux )x + f (x. but it is only ﬁrst order accurate.y) global m h x k = length(y). where g1(t) and g2(t) are two matlab functions for the boundary conditions at x = a and x = b. the ﬁnal time is T = 10 and β = 100. if h = 0. then we need 2 × 107 steps to get the solution at the ﬁnal time. i.e. for i=2:m-2 yp(i) = (y(i-1) -2*y(1) + y(2))/(h*h) + f(t. without compromising stability and computational complexity. e.3 The Crank-Nicolson scheme The time step constraint Δt = h2 /(2β) for the explicit Euler method is generally considered to be a severe restriction. 4.01. and f (t.1) 2 2 2 8 Intuitively. is the Crank-Nicolson scheme.. t) . yp(1) = (-2*y(1) + y(2))/(h*h) + f(t.x(1)) + g1(t)/(h*h).1). end yp(m-1) = (y(m-2) -2*y(m-1) )/(h*h) + f(t.1 Let φ(t) be a function that has continuous ﬁrst and second order derivatives. φ(t) ∈ C 2 . If we want second order accuracy O(h2 ). we need to take Δt = O(h2 ). Lemma 4..o.x(i)) + g2(t)/(h*h). x) is the source term.t . Then   1 Δt Δt (Δt)2  φ(t) = φ(t − ) + φ(t + ) + u (t) + h. yp=size(k. Li function yp = yfun-mol(t.g.

2 1  f (x. 2 At each time step. t + Δt) = f (x. by averaging the time level tk and tk+1 of the spatial derivative ∇·(β∇u)) and f (x. the method is the explicit Euler method. t + Δt/2) + O((Δt)2 ). then the method is unconditionally stable. the method is the backward Euler method. t). Δt When θ = 1. taking β = 1 for simplicity:  2 u(x. we need to solve a tridiagonal system of equations to get Uik+1 . t) − 2u(x. This can easily be seen using the following relations. Thus it has the following form k U k − (β k βi− k )U k + β k U k + βi+ Uik+1 − Uik 1 2 i−1 i− 12 1 2 i i+ 12 i+1 = Δt 2h2 (4.. and we can take Δt  h and have second order accuracy. it is much more eﬃcient than the explicit Euler method since it is second order accurate both in time and space with the same computational complexity. The θ-method is generally ﬁrst order in time and second order in space. t) + f (x. t + Δt) − u(x. t) = uxx (x. tk +Δt/2). we will prove it is unconditionally stable for the heat equation. t) + uxx (x. 2h2 u(x − h. Δt 3 2 u(x − h. t) + O(h2 ). t + Δt) + u(x + h. t + Δt) = uxx (x. The θ-method The θ. it is the Crank-Nicolson scheme. Although the Crank-Nicolson scheme is an implicit method. and otherwise it is conditionally stable. t) + u(x + h.2) k+1 k+1 k+1 k+1 k+1 k+1 k+1 1 Ui−1 − (β βi− i− 1 + βi+ 1 )Ui + βi+ 1 Ui+1 1  + 2 2 2 2 + fik + fik+1 . t + Δt) = uxx (x. t + Δt/2) + O((Δt)2 ) . t + Δt) − 2u(x. t + Δt/2) + + O((Δt)4 ). t) 1 Δt = ut (x. t + Δt) + O(h2 ) . In the next section. i. t) has the following form: Uik+1 − Uik 2 = θδxx Uik + (1 − θ)δxx 2 Uik+1 + θfik + (1 − θ)fik+1 .FD methods for linear parabolic PDE 69 at (xi . there is a time step constraint. 2h2 1  uxx (x.method for the heat equation ut = uxx + f (x. and when θ = 1/2. 2h2 2 The discretization is second order in time (central at t + Δt/2 with step size Δt/2) and second order in space. If 0 < θ ≤ 1/2. The com- putational cost is only slightly more than the explicit Euler method in one space dimension.e. when θ = 0. . except when θ = 1/2.

However. t).j+1 − 4Uijk+1 = + fijk+1 .j k+1 + Ui+1.1) k+ 1 k+ 12 k+ 1 k+ 12 Uijk+1 − Uij 2 Ui−1. and it is unconditionally stable. The coeﬃcient matrix for the unknown Uijk+1 is block tridiagonal.1 The backward Euler method (BW-CT) in 2D The backward Euler scheme can be written as Uijk+1 − Uijk k+1 Ui−1. (Δt)/2 h2x 2 hy (4. We can use symbolic expressions to discuss the method. 4. t) ∈ C 4 . The idea is to use an implicit discretization in one direction and an explicit discretization in another direction.j−1 k + Ui.j − 2Uij 2 + Ui+1.j+1 k k+ 1 = + + fij 2 . the ADI method is k+ 12 k+ 1 k+ 12 k+ 1 Uij − Uijk 2 Ui−1.j−1 + Ui.2) k+ 12 Δt 2 k+ 12 Δt 2 k+1 Δt k+ 12 Uijk+1 = Uij + δ U + δ U + f .j − 2Uij 2 + Ui+1. rewritten as k+ 12 Δt 2 k+ 12 Δt 2 k Δt k+ 12 Uij = Uijk + δ U + δ U + f .j k+1 Ui. (Δt)/2 h2x h2y which is second order in time and in space if u(x. 4.j + Ui.j−1 − 2Uijk + Ui. and strictly row diagonally dominant if the natural row ordering is used to index the Uijk+1 and the FD equations. The scheme is uncon- ditionally stable for linear problems.2 The Crank-Nicolson (C-N) scheme in 2D The Crank-Nicolson scheme can be written as  k+1 Uijk+1 − Uijk k+1 k+1 k+1 1 Ui−1.70 Z. 2 xx ij 2 yy ij 2 ij (4. if we use the natural row ordering.j + Ui+1.j−1 k+1 + Ui. we need to solve a system of equations with a strictly row diagonally dominant and block tridiagonal coeﬃcient matrix.j−1 − 2Uijk+1 + k+1 Ui.j+1 − 4Uijk k + + fij . (4. Li 4.j k + Ui+1. y.j+1 − 4Uij k+1 = + fijk+1 Δt 2 h2  (4. For the heat equation ut = uxx + uyy + f (x.j k+1 + Ui.j+1 k+ 12 = + + fij .4) k Ui−1. 2 xx ij 2 yy ij 2 ij . h2   Both the local truncation error and global error are O (Δt)2 + h2 .3) Δt h2 which is ﬁrst order in time and second order in space. It is unconditionally stable for linear problems.4 The alternating directional Implicit (ADI) method The ADI is a time splitting or fractional step method.3. A structured multigrid method can be applied to solve the linear system of equations from the backward Euler method or the Crank-Nicolson scheme.3.j k + Ui. y.j k Ui.

in matrix-vector form we have     Δt 2 1 Δt 2 Δt k+ 1 I− Dx Uk+ 2 = I+ Dy U k + F 2. we get a tridiagonal system of equations for U1j 2 . U2j 2 .3) Δt 2 k+1 Δt 2 1 Δt k+ 1 I− Dy U = I+ Dx Uk+ 2 + F 2. assuming a Dirichlet boundary condition at x = a and x = b. From the ﬁrst equation.4.FD methods for linear parabolic PDE 71 Thus on moving unknowns to the left-hand side. 2 x 2 2 This is the equivalent one step time marching form of the ADI method. 2 2 2 leading to a simple analytically convenient result as follows. 2 x 2 y 2 x 2 and substituting into the second equation yields        Δt 2 k+1 Δt 2 Δt 2 −1 Δt 2 I− D U = I+ D I− D I+ D Uk 2 y 2 x 2 x 2 y    Δt 2 Δt 2 −1 Δt k+ 1 Δt k+ 1 + I+ D I− D F 2+ F 2. 2 2 2     (4.1 Implementation of the ADI algorithm The key idea of the ADI method is to use the implicit discretization dimension by dimension. · · · . which will be use to show the stability of the ADI method later. 2 x 2 x 2 2 We can go further to get       Δt 2 Δt 2 k+1 Δt 2 Δt 2 I− D I− D U = I+ D I+ D Uk 2 x 2 y 2 x 2 y   Δt 2 Δt k+ 1 Δt k+ 1 + I+ D F 2+ F 2. 2 xx ij 2 yy ij 2 ij k+ 1 k+ 1 k+ 1 For ﬁxed j. Note that in this derivation we have used       Δt 2 Δt 2 Δt 2 Δt 2 I+ D I+ D = I+ D I+ D 2 x 2 y 2 y 2 x and other commutative operations. 4.  −1     k+ 12 Δt 2 Δt 2 k Δt 2 −1 Δt k+ 1 U = I− D I+ D U + I− D F 2. Um−1.j 2 . by taking advantage of fast tridiagonal solvers for k+ 12 Δt 2 k+ 12 Δt 2 k Δt k+ 12 Uij = Uijk + δ U + δ U + f . The system of equations in matrix- .

⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ k+ 1 ⎥ ⎢ −μ 1 + 2μ −μ ⎥ ⎢ U 2 ⎥ ⎣ ⎦ ⎢ m−2..j+1 ⎢ 2 ⎥ ⎢   ⎥ ⎢ k Δt k+ 12 k k k ⎥ ⎢ U2.. For each j.x(i).j + fm−1.4.j ⎥ ⎣   ⎦ k Δt k+ 12 k k k 1 Um−1..j k + U1. ⎥=F ⎢ . if i == 2 b(i-1) = b(i-1) + uexact(t2..x(i-1).j k + U3.j + Um−1. f(t2.x(i+1). ⎥ ⎢ ⎥ ⎢   ⎥ ⎢ k Δt k+ 12 k k k ⎥ ⎢ Um−2.j−1 − 2Um−1. ⎢ ⎥ ⎢ .i) = -1/h1.2 A pseudo-code of the ADI method in Matlab for j = 2:n. and fi 2 = f (xi . yj )k+ 2 + μ U1..72 Z. yj )k+ 2 2 k+ 1 1 and μ = βΔt 2h2 .m-1). % Loop for fixed j A = sparse(m-1.j+1 ⎥ ⎢ 2 ⎥ ⎢   ⎥ ⎢ Δt k+ 1 ⎥ ⎢ k U3j + k f3j 2 + μ U3.j−1 − 2U2. b=zeros(m-1.i-2) = -1/h1. else .j−1 − 2Um−2. for i=2:m. b(i-1) = (u1(i. Li vector form is ⎡ ⎤ ⎡ ⎤ k+ 1 −μ U1j 2 1 + 2μ ⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥⎢ k+ 1 ⎥ ⎢ −μ 1 + 2μ −μ ⎥ ⎢ U2j 2 ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥⎢ 1 ⎥ ⎢ −μ 1 + 2μ −μ ⎥ ⎢ U k+ 2 ⎥ ⎢ ⎥ ⎢ 3j ⎥ ⎢ ⎥⎢ . ⎥ ⎢ .y(j))/h1.y(j))/h1.j+1 ⎥ ⎢ ⎥  F=⎢ 2 ⎥.. ⎥⎢ .1). 4.j−1 k − 2U3.j + Um−2.y(j)) + 2*u1(i.j)/dt. The cost for the x-sweep is about O(5mn).j) + u1(i.j + f1j + μ ubc (a.j + U2. ⎥⎢ ⎥ ⎢ ⎥⎢ .j+1 ⎥ ⎢ 2 m−2.j+1 + μ ubc (b. ..j ⎥ ⎣ ⎦ −μ 1 + 2μ k+ 12 Um−1. . ⎥ ⎢ .j + f2j + μ U2.j where ⎡ Δt k+ 12 1   ⎤ k U1. tk+ 2 ). . A(i-1.j + f + μ Um−2. we need to solve a symmetric tridiagonal system of equations.j-1) -2*u1(i.j + μ Um−1. A(i-1. else if i==m b(i-1) = b(i-1) + uexact(t2.j+1))/h1 + .j−1 k k − 2U1. .

i-1) = 2/dt + 2/h1. end end A(j-1. (4. we get Uijk+1 − Uijk k+ 12   k+ 1 2 = 2δxx Uij 2 + δyy Uijk+1 + Uijk + 2fij 2 . end ut = A\b.6) 4 Δt 2 . b(j-1) = (u2(i-1.1) together.4) we get   (Δt)2 2 2 Uijk+1 − Uijk  2 2  Uijk+1 − Uijk k+ 1 1+ δxx δyy = δxx + δyy + fij 2 . A(i-1. if j == 2 b(j-1) = b(j-1) + uexact(t1.3 Consistency of the ADI method Adding the two equations in (4. else if j==n b(j-1) = b(j-1) + uexact(t1. (4.j)/dt.1).j) + u2(i+1.4) (Δt)/2 and if we subtract the ﬁrst equation from the second equation.i) = -1/h1..j-2) = -1/h1. for j=2:n.x(i). A(j-1. we get k+ 1     4Uij 2 = 2 Uijk+1 + Uijk − Δtδyy 2 Uijk+1 − Uijk .x(i). %-------------.y(j-1))/h1.j) = -1/h1.loop in the y direction -------------------------------- for i = 2:m.m-1).y(j)) + 2*u2(i.FD methods for linear parabolic PDE 73 A(i-1.j-2) = -1/h1. (4.j) = -1/h1. % Solve the diagonal matrix. 4. b=zeros(m-1. A = sparse(m-1.4.5) Substituting this into (4. A(j-1. end end A(i-1.j-1) = 2/dt + 2/h1.i-2) = -1/h1.y(j+1))/h1. A(j-1.j) -2*u2(i.x(i).j))/h1 + . % Solve the system end ut = A\b.. else A(j-1. f(t2.

.4) Δt Δt We need u1 to get the scheme above started. due to the advec- tion term w · ∇u. (4. Li and we can clearly see that the discretization is second order accurate in both space and time. unless w is very large. We can use the explicit Euler method (FW-CT) to approximate u1 . the steady state solution of the parabolic PDE ut = ∇ · (β∇u) + w · u + f (x.e.6 Solving elliptic PDE using numerical methods for parabolic PDE We recall the steady state solution of a parabolic PDE is the solution of the corresponding elliptic PDE. since the term only contains the ﬁrst order partial derivatives and the CFL constraint is not an issue.2) 2 2 We treat the advection term implicitly. The time step constraint is h Δt ≤ . 4. it is not so easy to get a second order implicit scheme such that the coeﬃcient matrix is diagonally dominant or symmetric positive or negative deﬁnite. (4. t) .3) 2 w 2 At each time step. (4.1) Δt 2 where 1 3 1 (w · ∇h u)k+ 2 = (w · ∇h u)k − (w · ∇h u)k−1 . Tijk = O((Δt)2 + h2 ). One approach is to use an implicit scheme for the diﬀusion term and an explicit scheme for the advection term.5 An implicit-explicit method for diﬀusion and advection equations Consider the equation ut + w · ∇u = ∇ · (β∇u) + f (x. y. t) .g.. of the following form from time level tk to tk+1 : uk+1 − uk 1 1  1 + (w · ∇h u)k+ 2 = (∇h · β∇h u)k + (∇h · β∇h u)k+1 + f k+ 2 . as this should not aﬀect the stability and global error O((Δt)2 + h2 ). (4.74 Z. we need to solve a generalized Helmholtz equation 2uk+1 2uk 1 1 (∇ · β∇u)k+1 − =− + 2 (w · ∇u)k+ 2 − (∇ · β∇u)k − 2f k+ 2 . e. In this case. 4. i.

especially for nonlinear problems where the solution is not unique. but the boundary condition is relevant. Compare this method with FW-CT. h4 ). if the limit f¯(x) = lim f (x. The initial condition is irrelevant to the steady state solution. (Note: The stability condition of the scheme is βμ ≤ 32 ). 3. Find the order of the discretization. We can control the variation of the intermediate solutions. where 2 Ui−1 − 2Ui + Ui+1 δxx Ui = . and Crank-Nicolson schemes and explain the advantages and limitations. For the implicit Euler method applied to the heat equation ut = uxx . 2. we prefer to use implicit methods with large time steps since the accuracy in time is unimportant. t) t→∞ exists.FD methods for linear parabolic PDE 75 is the solution to the elliptic PDE ∇ · (β∇u) + w · u + f¯(x) = 0 . μ = Δt/h2 is consistent with the heat equation (4.2) 2 Δt 12 for the heat equation (4. Since we only require the steady state solution. BW-CT.1) of the form 1−α k  Uik+1 = αUik + k Ui+1 + Ui−1 2 where α = 1 − 2βμ.1) has order of accuracy ((Δt)2 . 4. Show that a scheme for ut = β uxx (4.7 Exercises 1. is it possible to choose Δt such that the discretization is O((Δt)2 + h4 )? . This approach has some advantages. h2 and Δt = O(h2 ). Show that the implicit scheme    k+1    Δtβ 2 Ui − Uik h2 2 2 1− δxx =β 1− δxx δxx Uik (4. and the linear system of equations is more diagonally dominant.1).

Assume that u is the temperature of a thin rod with one end (x = b) just heated. u(x. Implement and compare the ADI and Crank-Nicolson methods with the SOR(ω) (try to test optimal ω) for the following problem involving the 2D heat equation: ut = uxx + uyy + f (t. Li 4. a < x < b. comparison of cputime. f (x. where Uj−1 − 2Uj + Uj+1 δx2 Uj = and 0 ≤ θ ≤ 1 . y) = u0 (x. h2 7. t≥0. The other end of the rod has a room temperature (70o C). x. Roughly how long does it take for the temperature of the rod to reach the steady state? What is the exact solution of the steady state? 2 Hint: Take the initial condition as u(x. where β is a constant. . t) = 0. β>0. tf inal = 1. t). Δt 2h h2 5.4) k for the heat equation ut = buxx . y) . Use u(x. c ≤ y ≤ d.76 Z. y). 0 < x < 1.3) Use the von Neumann analysis to derive the time step restriction for the scheme Uik+1 − Uik U k − Ui−1 k U k − 2Uik + Ui+1 k + i+1 = β i−1 . You can use Matlab code ode15s or ode23s to solve the semi-discrete ODE system. Implement and compare the Crank-Nicolson and the MOL methods using Matlab for the heat equation: ut = βuxx + f (x. t) = (cos t) x2 sin(πx). Consider the diﬀusion and advection equation ut + ux = βuxx . Your discussion should include the grid reﬁnement analysis. where T0 and γ are two constants. ux (b. t) = g1 (t). t ≥ 0. and the Neumann boundary condition ux (b. a<x<b. Solve the problem and ﬁnd the history of the solution. 0) = T0 e−(x−b) /γ . and any conclusions you can draw from your results. Carry out the von Neumann analysis to determine the stability of the θ method Uj (n+1) − Ujn   (n) (n+1) = b θ δx2 Uj + (1 − θ) δx2 Uj (4. t) = g2 (t). error and solution plots for m = 80. (4. 6.0 to test and debug your code. Write a short report about these two methods. t) = 0. u(a. 0) = u0 (x). u(0. x.

Your discussion should include the grid reﬁnement analysis (with a ﬁxed ﬁnal time. Choose two examples with known exact solutions to test and debug your code. . Write a short report about the two methods. and any conclusions you can draw from your results.FD methods for linear parabolic PDE 77 and Dirichlet boundary conditions. say T = 0.5). error and solution plots. comparison of cpu time and ﬂops.