You are on page 1of 6

FINITE DIFFERENCE METHODS

LONG CHEN

The best known methods, nite difference, consists of replacing each derivative by a difference quotient in the classic formulation. It is simple to code and economic to compute. In a sense, a nite difference formulation offers a more direct approach to the numerical solution of partial differential equations than does a method based on other formulations. The drawback of the nite difference methods is accuracy and exibility. Standard nite difference methods requires more regularity of the solution (e.g. u C 2 ()) and the triangulation (e.g. uniform grids). Difculties also arises in imposing boundary conditions. 1. F INITE DIFFERENCE FORMULA In this section, for simplicity, we discuss Poisson equation posed on the unit square = (0, 1) (0, 1). Variable coefcients and more complex domains will be discussed in nite element methods. Furthermore we assume u is smooth enough to enable us use Taylor expansion freely. Given two integer m, n 2, we construct a rectangular grids Th by the tensor product of two grids of (0, 1): {xi = (i 1)hx , i = 1, m, hx = 1/(m 1)} and {yj = (j 1)hy , j = 1, n, hy = 1/(n 1)}. Let h = max{hx , hy } denote the size of Th . We denote h = Nh (Th ) and h = {(xi , yj ) }. See Figure 1.

F IGURE 1. Uniform Grid We consider the discrete function space given by Vh = {uh (xi , yj ), 1 i m, 1 j n} which is isomorphism to RN with N = m n. It is more convenient to use sub-index (i, j) for the discrete function: ui,j := uh (xi , yj ). For a continuous function u C(), the interpolation operator Ih : C() Vh maps u to a discrete function and will be denoted by uI . By the denition (uI )i,j = u(xi , yj ). Note that the value of a discrete function is only dened at grid points.
Date: Updated September 22, 2011.
1

LONG CHEN

Similar denitions can be applied to one dimensional case. Choose a mesh size h and u Vh ((0, 1)). Popular difference formulas at an interior node xj for a discrete function u Vh include: uj uj1 The backward difference: (D u)j = ; h uj+1 uj The forward difference: (D+ u)j = ; h uj+1 uj1 The centered difference: (D u)j = ; 2h uj+1 2uj + uj1 . The centered second difference: (D2 u)j = h2 It is easy to prove by Talyor expansion that (D u)j u (xj ) = O(h), (D u)j u (xj ) = O(h2 ), (D+ u)j u (xj ) = O(h), (D2 u)j u (xj ) = O(h2 ).

We shall use these difference formulation, especially the centered second difference to approximate the Laplace operator at an interior node (xi , yj ):
2 2 (h u)i,j = (Dxx u)i,j + (Dyy u)i,j ui+1,j 2ui,j + ui1,i ui,j+1 2ui,j + ui,j1 = + . 2 hx h2 y

It is called ve point stencil since only ve points. When hx = hy , it is simplied to (1) (h u)i,j = ui+1,j + ui1,i + ui,j+1 + ui,j1 4ui,j . h2

For the right hand side, we simply take node values i.e. fi,j = (fI )i,j = f (xi , yj ). The nite difference methods for solving Poisson equation is simply (2) (h u)i,j = fi,j , 1 i m, 1 j n,

with appropriate processing of boundary conditions. Here in (2), we also use (1) for boundary points but drop terms involving grid points outside of the domain. Let us give an ordering of N = m n grids and use a single index k = 1 to N for uk = ui(k),j(k) . For example, the index map k (i(k), j(k)) can be easily written out for the lexicographically ordering. With any choosing ordering, (2) can be written as a linear algebraic equation: (3) Au = f ,

where A RN N , u RN and f RN . Remark 1.1. There exist different orderings for the grid points. Although they give equivalent matrixes up to permutations, different ordering does matter when solving linear algebraic equations. 2. B OUNDARY CONDITIONS The equation (2) is not complete since the operator h is not well dened on the boundary. We shall discuss how to deal with boundary conditions in nite difference methods.

FINITE DIFFERENCE METHODS

Dirichlet boundary condition. For the Poisson equation with Dirichlet boundary condition (4) u = f in , u = g on 1 = , the value on the boundary is given by the boundary conditions. Namely ui,j = g(xi , yj ) for (xi , yj ) and thus not unknowns in the equation. There are several ways to close the equation for Dirichlet boundary condition. One solution is to let aii = 1, aij = 0, j = i for a node xi 1 and fi = g(xi ). Another solution is to modify the right hand side at interior nodes. For example, let us consider a simple example with 9 nodes. The only unknowns is u5 . By the formula of discrete Laplace operator at that node, we obtain the adjusted equation 1 4 u5 = f5 + 2 (u2 + u4 + u6 + u8 ). h2 h We use the following Matlab code to illustrate the implementation of Dirichlet boundary condition. Suppose bdNode is a logic array representing boundary nodes in the way: bdNode(k)=1 if (xk , yk ) and bdNode(k)=0 otherwise.
1 2 3 4 5 freeNode = bdNode; u = zeros(N,1); u(bdNode) = g(node(bdNode,:)); f = f-A*u; u(freeNode) = A(freeNode,freeNode)\f(freeNode);

The matrix A(freeNode,freeNode) is an SPD (see Exercise 1) and thus ensure the existence of the solution. Neumann boundary condition. For the Poisson equation with Neumann boundary condition u = g on , u = f in , n there is a compatible condition for f and g: u (5) f dx = u dx = dS = g dS. n A natural approximation is using one side difference, for example: u u2,j u1,j (x1 , yj ) = + O(h), n h could be a choice. But comparing the center difference for , this is only a rst order approximation. To treat Neumann boundary condition more accurately, we need to introduce the ghost points next to the boundary. We extend the lattice by allowing the index 0 i, j n + 1. Then we can use center difference scheme: u u0,j u2,j (x1 , yj ) = + O(h2 ). n 2h The value u0,j is not well dened. We need to eliminate it from the equation. It is possible since on the boundary point (x1 , yj ), we have two equations: (6) (7) 4u1,j u2,j u0,j u1,j+1 u1,j1 = h2 f1,j u0,j u2,j = 2h g1,j .

From (7), we get u0,j = 2h g1,j u2,j . Substituting it into (6) and scaling by a factor 1/2, we get an equation at point (x1 , yj ): 2u1,j u2,j 0.5 u1,j+1 0.5 uj1 = 0.5 h2 f1,j h g1,j .

LONG CHEN

The scaling is to preserve the symmetry of the matrix. We can deal with other boundary points except four corner points by the same technique. At corner points, even the norm vector n(0, 0) is not well dened. We use average of two directional derivatives to get an approximation. (8) (9) (10) 4u1,1 u2,1 u0,1 u1,1 u1,0 = h2 f1,1 , u0,1 u2,1 = 2h g1,1 , u1,0 u1,2 = 2h g1,1 .

So we can solve u0,1 and u1,0 from (9) and (10), and substitute them into (8). Again to maintain the symmetric of the matrix, we multiply by 1/4. This gives an equation for the corner point (x1 , y1 ) u1,1 0.5 u2,1 0.5 u1,1 = 0.25 h2 f1,1 h g1,1 . Similar technique will be used to deal with other corner points. We then end with a linear algebraic equation Au = f . It can be shown that the corresponding matrix A is still symmetric but only semi-denite (see Exercise 2). The kernel of A consists of constant vector i.e. Au = 0 if and only if u = c. This implies a discrete version of the compatible condition (5):
N

(11)
i=1

fi = 0. 3. E RROR ESTIMATE

In order to analyze the error, we need to put the problem into a norm space. A natural norm for the nite linear space Vh is the maximum norm: v
,h

1in+1, 1jm+1

max {|vi,j |},

v Vh .

The subscript h indicates this norm depends on the triangulation since for different h, we have different numbers of vi,j . Note that this is the l norm for RN . We shall prove 1 : (Vh , ,h ) (Vh , ,h ) is stable. The proof will use h the discrete maximal principal and barrier functions. Theorem 3.1 (Discrete Maximum Principle). Let v Vh satisfy h v 0. Then max v max v.
h h

Equality holds if and only v is constant. Proof. Suppose maxh v > maxh v. Then we can take an interior node x0 where the maximum is achieved. Let x1 , x2 , x3 , and x4 be the four neighbors used in the stencil. Then
4 4

4v(x0 ) =
i=1

v(xi ) h2 h v(x0 )
i=1

v(xi ) 4v(x0 ).

Thus equality holds throughout and v achieves its maximum at all the nearest neighbors of x0 as well. Applying the same argument to the neighbors in the interior, and then to their neighbors, etc, we conclude that v is constant.

FINITE DIFFERENCE METHODS

Theorem 3.2. Let uh be the equation of (12) Then (13) uh


,h

h uh = fI at h \h ,

uh = gI at h .

1 fI 8

,h \h

+ gI

h, .

Proof. We introduce the comparison function = 1 1 1 (x )2 + (y )2 , 4 2 2


,h \h .

which satises h I = 1 at h \h and 0 1/8. Set M = fI h (uh + M I ) = h uh + M 0, so

Then

1 max uh max(uh + M I ) max(uh + M I ) max gI + M. h h h h 8 Thus uh is bounded above by the right-hand side of (13). A similar argument applies to uh giving the theorem. Corollary 3.3. Let u be the solution of the Dirichlet problem (4) and uh the solution of the discrete problem (12). Then uI uh
,h

1 h uI (u)I 8

,h \h . h, .

The next step is to study the consistence error h uI (u)I Lemma can be easily proved by Taylor expansion. Lemma 3.4. If u C 4 (), then h uI (u)I
,h \h

The following

h2 4u max{ 6 x4

,h \h ,

4u y 4

,h \h }.

We summarize the convergence results on the nite difference methods in the following theorem. Theorem 3.5. Let u be the solution of the Dirichlet problem (4) and uh the solution of the discrete problem (12). If u C 4 (), then uI uh with constant C= 1 4u max{ 48 x4
, ,h

Ch2 , 4u y 4

}.

In practice, the second order of convergence can be observed even the solution u is less smooth than C 4 (), i.e. the requirement u C 4 (). This restriction comes from the point-wise estimate. In nite element method, we shall use integral norms to nd the right setting of function spaces.

LONG CHEN

4. E XERCISES (1) Prove the following properties of the matrix A formed in the nite difference methods for Poisson equation with Dirichlet boundary condition: (a) it is symmetric: aij = aji ; N (b) it is diagonally dominant: aii j=1,j=i aij ; t (c) it is positive denite: u Au 0 for any u RN and ut Au = 0 if and only if u = 0. (2) Let us consider the nite difference discritization of Poisson equation with Neumann boundary condition. (a) Write out the 9 9 matrix A for h = 1/2. (b) Prove that in general the matrix corresponding to Neumann boundary condition is only semi-positive denite. (c) Show that the kernel of A consists of constant vectors: Au = 0 if and only if u = c. (3) Implement nite difference methods for solving the Poisson equation u = f with pure Dirichlet or pure Neumann boundary in the unit interval (0, 1). (a) Discretize the domain into uniform grid. (b) Discretize the operator for interior points. (c) Modify the equation for boundary points. (d) Use director solver in Matlab to compute the solution: u = A\f. (e) Choose a smooth function and substitute into Poisson equation to get a right hand side function. Then compare your computation with the true solution in the discrete maximal norm, i.e., compute uI uh and show the rate of convergence.

You might also like