Top Banner

of 23

5a Finite Difference

Apr 14, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/27/2019 5a Finite Difference

    1/23

    5

    Overview of Discretization

    Methods

    5.1 Finite-Difference Method

    5.1.1 Basic Ideas: Collocation and Truncation

    The basic idea underlying the finite-difference method is two-fold:1. At each discrete location at which the governing equation is to be solved

    numerically, replace the spatial derivatives by discrete derivatives. Takingthe Burgers equation as an example, we can write the semi-discrete equationat the location x0 as

    du

    dt

    x0

    + ux0u

    x

    x0

    = 0. (5.1)

    Note that we require the semi-discrete equation to be satisfied exactly.2. Discrete derivatives are approximated by divided differences of the function Although the infinitesimal

    calculus has been a splendid

    success, yet there remainproblems in which it is

    cumbrous or unworkable.

    When such difficulties are

    encountered it may be well

    to return to the manner in

    which they did things before

    the calculus was invented,

    postponing the passage to

    the limit until after the

    problem had been solved for

    a moderate number of

    moderately small

    differences.

    L.F. Richardson, 1927

    evaluated at discrete locations. This idea is simply based on the definition

    of the x-derivative of a function (x) at x0, namely,

    d

    dx

    x0

    = limx0

    (x0 + x) (x0)

    x. (5.2)

    The finite-difference method approximates the derivative by foregoing thelimiting process and evaluating the right-hand side of equation (5.2) at afinite value of x,

    x

    x0

    =(x0 + x) (x0)

    x. (5.3)

    The lack of the limiting process causes the so-called truncation error, which

    is discussed in more detail below.It is clear from the above that the precise manner in which the discrete deriva-

    tives are computed is the key to the accuracy of the finite-difference method.Before continuing to show how various finite-difference approximations can bederived, we provide a preliminary discussion of the accuracy of finite-differenceapproximations. More detailed discussions are presented in section 6.3.

    We can expect that the derivative will be approximated accurately for asmall but finite value of x provided that (x) is sufficiently smooth in theneighborhood ofx0. In fact, the mean-value theorem of calculus tells us that theapproximation will be exact at some point within the interval [ x0, x0 + x].

    29

  • 7/27/2019 5a Finite Difference

    2/23

    30 Overview of Discretization Methods

    x

    sss s E' E

    i i + 1 x ii 1

    s

    Figure 5.1: Finite-difference grid in one dimension.

    The vague statements about the accuracy of the approximation for small butfinite x can be made somewhat more precise by using Taylor series. For example,the Taylor-series expansion for (x0 + x) about x0 is

    (x0 + x) = (x0) + xd

    dx

    x0

    +(x)2

    2

    d2

    dx2

    x0

    +(x)3

    3!

    d3

    dx3

    x0

    + . . . . (5.4)

    Hence we can write

    d

    dx

    x0

    =(x0 + x) (x0)

    x

    x

    2

    d2

    dx2

    x0

    +(x)2

    3!

    d3

    dx3

    x0

    + . . .

    . (5.5)

    At this stage, it is convenient to identify locations such as x0 and (x0 + x) withvertices on a grid such as that depicted in figure 5.1. For simplicity, we assumethat the grid has constant spacing x. Hence each vertex can be addressed byan index i and the location x0 can be expressed as (ix). Equation (5.5) cannow be written

    d

    dx

    i

    =i+1 i

    x

    x

    2

    d2

    dx2

    i

    +(x)2

    3!

    d3

    dx3

    i

    + . . .

    . (5.6)

    We recognize the first term on the right-hand side as the finite-difference approx-imation given by equation (5.3). Written in terms of the grid point locations, thisso-called forward-difference approximation can be expressed as

    x

    i

    =i+1 i

    x. (5.7)

    Equation (5.7) can be interpreted geometrically as shown in figure 5.2(a). Withequation (5.7), equation (5.6) can be written as

    d

    dx

    i

    =

    x

    i

    x

    2

    d2

    dx2

    i

    +(x)2

    3!

    d3

    dx3

    i

    + . . .

    . (5.8)

    Hence we see that the derivative and its finite-difference approximation differ byan infinite series of terms. This infinite series of terms is the truncation error(te) alluded to above. The designation truncation error is motivated by thefact that, when the derivative is simply replaced by the discrete derivative, we

    are tacitly truncating after the first term on the right-hand side and incurring anerror in doing so.

    Each term in the te consists of products of fractions, powers of the gridspacing, and higher-order derivatives of the solution evaluated at the locationwhere the derivative is approximated. In the limit of x 0, the leading term ofthe te dominates subsequent terms if the function being approximated is smoothand we can write equation (5.6) as

    d

    dx

    i

    =i+1 i

    x+ O(x). (5.9)

    Id

  • 7/27/2019 5a Finite Difference

    3/23

    5.1. Finite-Difference Method 31

    i 1 i i + 1

    (x)

    i1

    i

    i+1

    ii1x

    i+1ix

    (a) Forward- and backward-difference approximations.

    i 1 i i + 1

    (x)

    i1

    i

    i+1

    i+1i12x

    (b) Central-difference approximation.

    Figure 5.2: Geometric interpretation of finite-difference approxima-tions to first derivative.

    The power of the grid spacing in the leading term of the te is called the order ofaccuracy of the approximation or simply the order of approximation. Accordingly,the forward-difference approximation is a first-order accurate approximation ofthe first derivative. It is important to note that the notation O(x) does notquantify the exact value of the te, but only its functional dependence as x 0.

    Note that the order of the derivative being approximated, the order of accuracyof the approximation, and the order of the derivative of the leading term in thetruncation error are related by dimensional arguments.

    The order of accuracy of a finite-difference approximation as defined aboveis also referred to as the nominal order of accuracy. This term is used todistinguish between the theoretical order of accuracy as specified when derivinga given finite-difference approximation and the order of accuracy achieved inpractice, the so-called actual order of accuracy. The determination of the actualorder of accuracy is described in sections 6.3.1 and 6.3.3.

    Id

  • 7/27/2019 5a Finite Difference

    4/23

    32 Overview of Discretization Methods

    5.1.2 Explicit Finite-Difference Approximations

    Equation (5.7) is termed an explicit finite-difference approximation because thederivative can be computed explicitly in terms of the function values. In sec-tion 5.1.3, we will discuss implicit finite-difference approximations in which thederivative at a given point depends on derivatives at other points.

    The approximation given by equation (5.7) is not the only possibility for com-puting the first derivative. By considering the Taylor series

    (x0 x) = (x0)xd

    dx

    x0

    +(x)2

    2

    d2

    dx2

    x0

    . . . (5.10)

    we can derive the first-order accurate backward-difference approximation

    x

    i

    =i i1

    x. (5.11)

    Similarly, we can combine equations (5.4) and (5.10) to eliminate (x0, y0) andobtain the second-order accurate central-difference approximation,

    xi

    =i+1 i1

    2x . (5.12)

    Equations (5.11) and (5.12) can be interpreted geometrically as shown in fig-ure 5.2(a) and figure 5.2(b). By including more points, i.e., Taylor-series ex-pansions for (x0 2x), for example, higher-order approximations to the firstderivative can be derived.

    Approximations for higher-order derivatives can also be derived. For example,adding equations (5.4) and (5.10) leads to the following second-order accurateapproximation

    2

    x2

    i

    =i+1 2i + i1

    (x)2. (5.13)

    Higher-order approximations for second derivatives can be derived similarly.

    5.1.2.1 Derivation of Finite-Difference Approximations

    In the above, Taylor series were employed to derive finite-difference approxima-tions. Several other methods can be used to derive finite-difference approxima-tions as detailed below. For simplicity, we assume uniform grid spacing, but thesemethods are applicable to arbitrary variations of the grid spacing. We begin bydescribing the Taylor-series method in a more formal setting.

    Taylor Series. The derivation of a finite-difference approximation to a givenderivative

    x

    i

    =d

    dx

    i

    + TE (5.14)

    starts by specifying the functional form of the approximation, i.e.,

    x

    i

    =r

    j=l

    ji+j . (5.15)

    Note that we specify which grid points are included in the stencil, i.e., whichvalues contribute to the approximation. The goal is to compute the weights jsuch that the approximation attains a specified order of accuracy. DimensionalWe shall see later, e.g., in

    section 9.1.5, that attaining

    a specific order of accuracy

    is not always the most

    appropriate goal and that

    accuracy can be measured

    in more ways than just

    through the order ofaccuracy.

    considerations indicate that the weights must have dimensions of inverse length,i.e., j (x)

    1.

    Id

  • 7/27/2019 5a Finite Difference

    5/23

    5.1. Finite-Difference Method 33

    To make these ideas more specific, we first consider a specific example and thenproceed to the general case. Let us find a second-order accurate approximation for(d/dx)i using i, i+1, and i+2, i.e., we put l = 0 and r = 2 in equation (5.15)to get

    x i =2

    j=0

    ji+j = 0i + 1i+1 + 2i+2. (5.16)

    Next, we use Taylor-series expansions to express each term on the right-handside of the approximation given by equation (5.15) at the same grid point at whichthe left-hand side is evaluated. Expanding i+j about xi gives

    i+j = i +

    k=1

    (jx)k

    k!

    dk

    dxk

    i

    , (5.17)

    where we made use of the assumption of uniform grid spacing so that xi+j xi =jx. Therefore, we can rewrite equation (5.16) as

    x

    i

    = 0i

    + 1

    i + xd

    dxi

    +1

    2 (x)2

    d2

    dx2i

    +1

    3! (x)3

    d3

    dx3i

    + . . .

    + 2

    i + 2x

    d

    dx

    i

    +1

    2(2x)2

    d2

    dx2

    i

    +1

    3!(2x)3

    d3

    dx3

    i

    + . . .

    .

    Collecting terms gives

    x

    i

    = (0 + 1 + 2)i

    + (1x + 22x)d

    dx

    i

    +1

    2 1(x)2 + 2(2x)

    2

    d2

    dx2 i+

    1

    3!

    1(x)

    3 + 2(2x)3 d3

    dx3

    i

    + . . . .

    (5.18)

    We need to compute three weights and therefore have to extract as manyconditions from equation (5.18). These conditions can be derived by assigningspecific values to the terms in parentheses that multiply the function value andthe first and second derivatives:

    1. We require that (/x)i does not depend on i because adding a constantto a function does not change the derivative. Therefore the first conditionis

    0 + 1 + 2 = 0. (5.19)

    2. Our goal is for (/x)i to be an approximation to (d/dx)i and thereforethe second condition is

    1x + 22x = 1. (5.20)

    Equations (5.19) and (5.20) are also referred to as conditions for first-orderaccuracy. This is because if the weights satisfy only these two conditions(note this would leave one free parameter), the term in parentheses multi-plying the second derivative in equation (5.18) would become the TE and beO(x). Note that equation (5.19) by itself is sometimes called a conditionfor zeroth-order accuracy.

    Id

  • 7/27/2019 5a Finite Difference

    6/23

    34 Overview of Discretization Methods

    3. To obtain second-order accuracy, the weights also have to satisfy the thirdcondition

    1(x)2 + 2(2x)

    2 = 0. (5.21)

    The three conditions give a linear system that can be solved to obtain theweights,

    0 =

    3

    2x , 1 =

    2

    x , 2 =

    1

    2x . (5.22)

    Substituting back into equation (5.15) gives the desired approximation as

    x

    i

    =3i + 4i+1 i+2

    2x. (5.23)

    This simple approach to deriving finite-difference approximations can in principlebe used for any order derivative and any order of accuracy.

    i 0

    i00

    i000

    i

    (=x)i 0 1 0 0

    !0i !0 0 0 0

    !1i+1 !1 !1x 12!1(x)2 16!1(x)3

    !2i+2 !2 2!2x 2!2(x)2 4

    3!2(x)

    3

    ThisrowcontainsthefunctionvalueandderivativesintheTaylor-seriesexpansion.

    Thisentrycontainsthediscreteoperatorforwhichanexpressionissought.

    Theentriesinthiscolumn

    containthetermsthatappearintheexpressionforthediscreteoperator.

    Step1:Constructionofbasictable(firstrowandcolumn)

    Thislineservestoseparate

    thediscreteoperatorfromthetermsintheexpressionforthediscreteoperator(i.e.,theleft-andright-handsidesofEq.(x.yz)).

    i 0i 00

    i000

    i

    (=x)i 0 1 0 0

    !0i !0 0 0 0!1i+1 !1 !1x

    1

    2!1(x)

    2 1

    6!1(x)

    3

    !2i+2 !2 2!2x 2!2(x)2 4

    3!2(x)

    3

    Thisrowcontainsentriesthatspecifywhichcontinuousoperatoristobeapproximatedbythediscreteoperator.Here,the`1'belowthefirstderivativeindicatesthatthediscreteoperatorisanapproximationofthefirstderivative.

    Step2:Specificationofapproximation

    i 0i 00

    i000

    i

    (=x)i 0 1 0 0

    !0i !0 0 0 0!1i+1 !1 !1x

    1

    2!1(x)

    2 1

    6!1(x)

    3

    !2i+2 !2 2!2x 2!2(x)2 4

    3!2(x)

    3

    ThisrowcontainsthecoefficientsintheTaylor-seriesexpansionofmultipliedbytheweight.Therowsaboveandbelowaretreatedinthesamemanner.

    about

    i+1 xi

    Step3:Taylor-seriesexpansionofapproximation

    i 0i 00

    i000

    i

    (=x)i 0 1 0 0

    !0i !0 0 0 0!1i+1 !1 !1x

    1

    2!1(x)

    2 1

    6!1(x)

    3

    !2i+2 !2 2!2x 2!2(x)2 4

    3!2(x)

    3

    !0 + !1 + !2 = 0,

    !1x + 2!2x = 1,1

    2!1(x)

    2 + 2!2(x)2 = 0.

    Todeterminetheweights,theentriesabovetheseparationlineineachcolumnareequatedtothesumoftheentriesbelowtheseparationlineinthatcolumn.Thisisdoneforasmanycolumnsasthereareweightstobedetermined.

    Withthreeweightstobedetermined,weobtainfromthethreehighlightedcolumnsthelinearsystem

    Step4:Determinationofweights

    Figure 5.3: Construction and use of Taylor table for the derivation

    of the second-order accurate forward-difference approximation to thefirst derivative.

    The derivation of finite-difference approximations with Taylor series can bemade more systematic through the so-called Taylor table. The construction anduse of a Taylor table is explained in figure 5.3, taking the second-order accurateforward-difference approximation for the first derivative as an example. As in-dicated in the figure, the construction and use of a Taylor table can be dividedinto four steps. The main advantage of constructing Taylor tables is that the

    Id

  • 7/27/2019 5a Finite Difference

    7/23

    5.1. Finite-Difference Method 35

    conditions to be satisfied by the weights are easily extracted. For the specificexample considered here, the extracted conditions are equal to equations (5.20)and (5.21), of course, and we again obtain equation (5.23). To determine the te,we inspect the first column of the Taylor table that was not used to determinethe weights; in this case, the column for i . Rather than equating the entry inthe second row to the sum of those in the third, fourth, and fifth rows, we simply

    sum the entries of the latter, i.e.,

    TE =

    1

    61 +

    4

    32

    (x)3

    d3

    dx3

    i

    = 1

    3(x)2

    d3

    dx3

    i

    . (5.24)

    Taylor tables are especially useful for the derivation of implicit finite-differenceapproximations, which we will meet in section 5.1.3.

    Before presenting another method of deriving finite-difference approximations,we reconsider the Taylor-series approach in a general manner, make some obser-vations, and introduce some terminology that will be used in future sections andchapters. Assume we wish to approximate the nth derivative on a uniform gridwith spacing h, i.e.,

    n

    xni

    =1

    hn

    r

    j=l

    ji+j . (5.25)

    Using equation (5.17) and grouping terms gives

    n

    xn

    i

    =

    k=0

    hk

    k!

    dk

    dxk

    i

    rj=l

    jjk. (5.26)

    We observe immediately that the sum

    rj=l

    jjk

    plays a central role in the analysis of approximations. This sum is called the kthmoment of the weights or simply the kth weight moment. Now assume that wewant the approximation to have order of accuracy p. This suggests breaking thesum over k in the above equation as follows,

    n

    xn

    i

    =n1k=0

    hkn

    k!

    dk

    dxk

    i

    rj=l

    jjk

    +1

    n!

    dn

    dxn

    i

    rj=l

    jjn

    +

    p+n1

    k=n+1hkn

    k!

    dk

    dxk

    i

    r

    j=ljj

    k

    +

    k=p+n

    hkn

    k!

    dk

    dxk

    i

    rj=l

    jjk.

    (5.27)

    Therefore, we extract the following conditions for the approximation of the nthderivative to be pth-order accurate:

    rj=l

    jjk =

    0 for 0 k n 1,

    n! for k = n,

    0 for n + 1 k p + n 1.

    (5.28)

    Id

  • 7/27/2019 5a Finite Difference

    8/23

    36 Overview of Discretization Methods

    The first set of conditions ensures that we do not obtain an approximation of aderivative lower than n. The second condition leads to the discrete nth derivativebeing equal to the exact nth derivative for polynomials of degree n. The thirdset of conditions requires that the first non-zero term in the truncation error isO(hp). Overall, the weight moments thus must satisfy n + 1 + (p 1) = p + nconditions. To satisfy these conditions, we therefore require an equal number of

    degrees of freedom. These are provided by the r l +1 stencil weights. Therefore,we have derived the following important condition:

    r l + 1 = p + n or p = (r l + 1) n. (5.29)

    Lagrangian Polynomial Interpolation. An alternative way of determiningfinite-difference approximations is through the use of Lagrangian polynomial in-terpolation. Given a function (x) at r l + 1 points xj , the Lagrangian inter-polation polynomial is

    p(x) =r

    j=lLj(x) (xj) =

    r

    j=lLj(x) j , (5.30)

    where the Lagrangian basis functions are defined as

    Lj(x) =r

    k=lk=j

    x xkxj xk

    . (5.31)

    The basis functions are polynomials of degree r l and have the properties

    Lj(xi) = ij and

    rj=l

    Lj(x) = 1,

    where ij is the Kronecker delta.

    Discrete derivatives are formed from derivatives of the interpolation polyno-mial. Thus an approximation to the first derivative is determined from

    x

    i

    = p(xi) =r

    j=l

    Lj(xi) j , (5.32)

    where, from equation (5.31),

    Lj(x) =

    rm=lm=j

    rk=l

    k=j,m

    (x xk)

    r

    k=lk=j

    (xj xk)

    . (5.33)

    By way of example, consider the case with l = 0 and r = 2, for which we have

    p(x) =(x x1)(x x2)

    (x0 x1)(x0 x2)0 +

    (x x0)(x x2)

    (x1 x0)(x1 x2)1 +

    (x x0)(x x1)

    (x2 x0)(x2 x1)2.

    If x1 = x0 + h and x2 = x1 + h, p(x) can be written as

    p(x) =2(x x0) 3h

    2h20

    2(x x0) 2h

    h21 +

    2(x x0) h

    2h22. (5.34)

    Id

  • 7/27/2019 5a Finite Difference

    9/23

    5.1. Finite-Difference Method 37

    Therefore, we have that

    x

    0

    = p(x0) =30 + 41 2

    2h,

    consistent with equation (5.23).Analogously, an approximation to the second derivative is determined from

    2

    x2

    i

    = p(xi) =

    rj=l

    Lj (xi) j , (5.35)

    where, from equation (5.31) or equation (5.33),

    Lj (x) =

    rm=lm=j

    rn=l

    n=j,m

    rk=l

    k=j,m,n

    (x xk)

    rk=lk=j

    (xj xk)

    . (5.36)

    Approximations to higher derivatives can be derived in a similar manner. Notethat the discrete derivatives are obtained from the interpolation polynomial byexact differentiation. In general, the discrete derivative is approximate becausethe interpolation polynomial is approximate. If (x) is a polynomial of degreer l, the interpolation polynomial and the discrete derivative are exact.

    The above expressions for the first and second derivative are valid for non-uniform grids. For uniform grids, for which we have xi+j xi = jh, equa-tions (5.32) and (5.33) and equations (5.35) and (5.36) can be simplified to give

    xi

    =1

    h

    r

    j=l

    i+j

    rm=lm=j

    rk=l

    k=j,m

    (i k)

    rk=lk=j

    (j k)

    (5.37)

    and

    2

    x2

    i

    =1

    h2

    rj=l

    i+j

    rm=lm=j

    rn=l

    n=j,m

    rk=l

    k=j,m,n

    (i k)

    rk=lk=j

    (j k)

    . (5.38)

    Difference Calculus. Equations (2.27), (2.31), (2.34) and (2.36) provide uswith four methods of computing D.We are now in a position to derive forward finite-difference approximations by

    making use of equation (2.27) and equation (2.12) to give

    xD = ln(1 + +) = + 2+2

    +3+3

    4+4

    + . . . (5.39)

    Approximations are derived by retaining as many terms on the right-hand sideas required by the desired order of accuracy. The first neglected term determinesthe order of the truncation error. For example, to derive a second-order accurate

    Id

  • 7/27/2019 5a Finite Difference

    10/23

    38 Overview of Discretization Methods

    approximation, we retain only the first two terms because 3+/x (x)2 by

    equation (2.28). This gives

    D =1

    x

    +

    2+2

    + O

    (x)2

    (5.40)

    Therefore, we obtain

    Di =1

    x

    (i+1 i)

    1

    2(i+2 2i+1 + i)

    + O

    (x)2

    (5.41)

    and collecting terms gives the same result as equation (5.23).Backward finite-difference approximations are derived by using equation (2.31)

    together with equation (2.13) to get

    xD = ln(1 ) = +22

    +33

    +44

    + . . . (5.42)

    As with forward difference approximations, backward difference approximationsare derived by retaining as many terms on the right-hand side as required by thedesired order of accuracy.

    Centered finite-difference approximations are derived by expanding the right-hand side of equation (2.36) to get

    D =1

    xsinh1 0 =

    1

    x

    0

    306

    +3

    4050 . . .

    (5.43)

    This relation leads to the usual second-order accurate central difference approx-imation given by equation (5.12) if only the first term in parentheses on theright-hand side is retained. Retaining the second term in parentheses leads to afourth-order accurate approximation, but it involves function values at alternategrid points,

    Di =1

    48x

    (i+3 + 27i+1 27i1 + i3) + O (x)4 (5.44)Approximations that involve function values at alternate grid points admit spuri-ous solutions, as was discussed in section 4.1.2.2. Before addressing this deficiency,we turn to equation (2.34), which can be written as

    D =2

    xsinh1

    2

    =

    1

    x

    3

    24+

    3

    6405 . . .

    (5.45)

    This equation by itself is also not useful because it leads to expressions involvingfunction values at half-integer grid points. However, it can be made useful throughthe identity expressed by equation (2.23) written as

    1 = 1 + 2

    41/2

    = 1 2

    8+

    3

    1284

    5

    10246 + . . . (5.46)

    Multiplying equation (5.45) by equation (5.46) gives

    D =

    1 +

    2

    4

    1/22

    xsinh1

    2

    =

    x

    3

    6+

    5

    30 . . .

    (5.47)

    and using equation (2.19) we can express this as

    D =0

    x

    1

    2

    6+

    4

    30 . . .

    (5.48)

    Id

  • 7/27/2019 5a Finite Difference

    11/23

    5.1. Finite-Difference Method 39

    This expression will now involve only function values at integer grid points because appears only raised to even powers. Consider including only the first two termsin parentheses in equation (5.48). Then we obtain

    Di =0

    x

    1

    2

    6

    i =

    1

    x

    1

    12i+2 +

    2

    3i+1

    2

    3i1 +

    1

    12i2

    . (5.49)

    This approximation is fourth-order accurate because we truncated the series ex-pansion at the 4 term. Note that the term 0/(x) does not influence the orderof accuracy because 0 x.

    So far, we have considered only the derivation of finite-difference approxima-tions for the first derivative. One of the strengths of difference calculus is thathigher-order derivatives can be derived in a straightforward way. Consider firstforward-difference approximations, for which we obtain from equation (5.39)

    dn

    dxn= Dn =

    1

    (x)n[ln(1 + +)]

    n(5.50)

    Expanding the logarithm in a Taylor series gives

    Dn =1

    (x)n

    n+

    n

    2n+1+ +

    n(3n + 5)

    24n+2+

    n(n + 2)(n + 3)

    48n+3+ + . . .

    (5.51)

    Evaluating this expression gives the formulae listed in table 5.3.

    Conversely, backward-difference approximations for higher-order derivativescan be obtained from equation (5.42) as

    dn

    dxn= Dn =

    1

    (x)n[ln(1 )]

    n(5.52)

    Expanding the logarithm in a Taylor series gives

    Dn = 1(x)n

    n + n2

    n+1 + n(3n + 5)24n+2 + n(n + 2)(n + 3)48

    n+3 + . . .

    (5.53)Note the similarities between equations (5.51) and (5.53). Evaluating this expres-sion gives the negative of the formulae listed in table 5.3.

    Finally, centered-difference approximations for higher-order derivatives can beobtained from equation (2.34) as

    Dn =2n

    (x)n

    sinh1

    2

    n(5.54)

    Expanding the inverse hyperbolic sine in a Taylor series gives

    Dn = n

    (x)n

    1 n24

    2 + n64

    5n + 2290

    4 n45

    57

    + n 15

    + (n 1)(n 2)35

    6 . . .

    (5.55)

    Because of the n operator outside the square brackets, this formula generatesdifference approximations with function values at integer (half-integer) points forn even (uneven). Another expression for centered-difference approximations canbe derived from equation (5.47) as

    Dn =

    1 +

    2

    4

    1/22n

    (x)n

    sinh1

    2

    n(5.56)

    Id

  • 7/27/2019 5a Finite Difference

    12/23

    40 Overview of Discretization Methods

    Table 5.1: Weights andtruncation-error constantC for centered finite-difference approximationsof derivatives of order nand order of accuracy p.After Fornberg (1998b, p.

    16).

    j

    n p 4 3 2 1 0 1 2 3 4 C

    1 2 12

    0 12

    1

    6

    4 112

    2

    30 2

    3

    1

    12

    1

    30

    6 160

    3

    20

    3

    40 3

    4

    3

    20

    1

    60

    1

    140

    8 1280 4105

    15

    45 0

    45

    15

    4105

    1280

    1630

    2 2 1 2 1 112

    4 112

    4

    3

    5

    2

    4

    3

    1

    12

    1

    90

    6 190

    3

    20

    3

    2

    49

    18

    3

    2

    3

    20

    1

    90

    1

    560

    8 1560

    8

    315

    1

    5

    8

    5

    205

    72

    8

    5

    1

    5

    8

    315

    1

    560

    1

    3150

    3 2 12

    1 0 1 12

    1

    4

    4 18

    1 138

    0 138

    1 18

    7

    120

    6 7240

    3

    10

    169

    120

    61

    300 61

    30

    169

    120

    3

    10

    7

    240

    41

    3024

    4 2 1 4 6 4 1 16

    4 16

    2 132

    28

    3

    13

    22 1

    6

    7

    240

    67

    240

    2

    5

    169

    60

    122

    15

    91

    8

    122

    15

    169

    60

    2

    5

    7

    240

    41

    7560

    Note that because the product of the first two terms on the right-hand side isunity [cf. equation (2.23) or (5.46)], it does not need to be raised to power n.Expanding the inverse hyperbolic sine in a Taylor series gives

    Dn = n

    (x)n

    1

    n + 3

    242 +

    5n2 + 52n + 135

    57604 . . .

    (5.57)

    Because of the n operator outside the square brackets, this formula generatesdifference approximations with function values at half-integer (integer) points forn even (uneven).

    Algorithm for Computing Finite-Difference Approximation Weights.Fornberg (1988, 1998a) presented an algorithm for computing weights of finite-difference approximations of arbitrary order of accuracy for derivatives of arbi-trary order. With the definition

    dn

    dxn

    i

    =1

    xn

    rj=l

    j,ni+j + O [(x)p] (5.58)

    we can encompass centered (l = r), biased (l = r, l = 0, and r = 0), and one-sided(l = 0 and r > 0 or l > 0 and r = 0) approximations. The resulting weights arepresented in tables 5.1 and 5.3 for 1 n 4 and r + l 8. The tables alsolist the truncation-error constant C, i.e., the numerical constant appearing in theleading term of the truncation error,

    C(x)pdn+p

    dxn+p.

    Note that if the direction of biasing in the biased and one-sided approximationsis reversed, the weights change sign if the order of the derivative is odd.

    5.1.2.2 Explicit Finite Differences as Differentiation Matrices

    In the above, we have considered only the approximation to the derivative at aspecific point (i, j). We can also consider these approximations for an entire range

    Id

  • 7/27/2019 5a Finite Difference

    13/23

    5.1. Finite-Difference Method 41

    j

    n p 4 3 2 1 0 1 2 3 C

    1 3 16

    1 12

    1

    3

    1

    12

    4 112

    1

    2

    3

    2

    5

    6

    1

    4

    1

    20

    5

    1

    30

    1

    4

    1

    1

    3

    1

    2

    1

    20

    1

    60

    6 160

    2

    15

    1

    2

    4

    3

    7

    12

    2

    5

    1

    30

    1

    105

    7 1140

    1

    15

    3

    101 1

    4

    3

    5

    1

    10

    1

    105

    1

    280

    2 3 112

    1

    3

    1

    2

    5

    3

    11

    12

    1

    12

    4 112

    1

    2

    7

    6

    1

    3

    5

    4

    5

    6

    13

    180

    5 190

    1

    15

    1

    12

    10

    9

    7

    3

    19

    15

    13

    180

    1

    90

    3 3 14

    7

    4

    7

    2

    5

    2

    1

    4

    1

    4

    1

    8

    4 18

    1 298

    6 358

    1 18

    1

    15

    5 7120

    8

    15

    89

    40

    11

    3

    49

    24

    2

    5

    71

    120

    1

    15

    7

    240

    4 3 16

    1 32

    2

    3

    7

    23 5

    6

    1

    6

    Table 5.2: Weights andtruncation-error con-stant C for biased finite-difference approximationsof derivatives of order nand order of accuracy p.

    j

    n p 0 1 2 3 4 5 6 7 8 C

    1 1 1 1 12

    2 32

    2 12

    1

    3

    3 116

    3 32

    1

    3

    1

    4

    4 2512

    4 3 43

    1

    4

    1

    5

    5 13760

    5 5 103

    5

    4

    1

    5

    1

    6

    6 4920

    6 152

    20

    3

    15

    4

    6

    5

    1

    6

    1

    7

    7 363140

    7 212

    35

    3

    35

    4

    21

    5

    7

    6

    1

    7

    1

    8

    8 761280

    8 14 563

    35

    2

    56

    5

    14

    3

    8

    7

    1

    8

    1

    9

    2 1 1 2 1 1

    2 2 5 4 1 1112

    3 3512

    26

    3

    19

    2

    14

    3

    11

    12

    5

    6

    4 154

    77

    6

    107

    613 61

    12

    5

    6

    137

    180

    5 20345

    87

    5

    117

    4

    254

    9

    33

    2

    27

    5

    137

    180

    7

    10

    6 46990

    223

    10

    879

    20

    949

    1841 201

    10

    1019

    180

    7

    10

    363

    560

    7 295315040

    962

    35

    621

    10

    4006

    45

    691

    8

    282

    5

    2143

    90

    206

    35

    363

    560

    761

    1260

    3 1 1 3 3 1 32

    2 52

    9 12 7 32

    7

    4

    3 174

    71

    4

    59

    2

    49

    2

    41

    4

    7

    4

    15

    8

    4

    49

    8 29

    461

    8 62

    307

    8 13

    15

    8

    29

    15

    5 967120

    638

    15

    3929

    40

    389

    3

    2545

    24

    268

    5

    1849

    120

    29

    15

    469

    240

    6 80180

    349

    6

    18353

    120

    2391

    10

    1457

    6

    4891

    30

    561

    8

    527

    30

    469

    240

    1791

    917

    4 1 1 4 6 4 1 2

    2 3 14 26 24 11 2 176

    3 356

    31 1372

    242

    3

    107

    219 17

    6

    7

    2

    4 283

    111

    2142 1219

    6176 185

    2

    82

    3

    7

    2

    967

    240

    5 106980

    1316

    15

    15289

    60

    2144

    5

    10993

    24

    4772

    15

    2803

    20

    536

    15

    967

    240

    89

    20

    Table 5.3: Weights andtruncation-error constantC for one-sided finite-difference approximationsof derivatives of order nand order of accuracy p.After Fornberg (1998b, p.17).

    Id

  • 7/27/2019 5a Finite Difference

    14/23

    42 Overview of Discretization Methods

    of points, such as (1 i M, j). The approximate derivative then becomes amatrix-derivative operator acting on 1iM,j to produce

    1iM,j . Such matrix

    operators may be thought of as finite-dimensional discrete analogues of infinite-dimensional continuous differentiation operators. Interpreting finite differencesas matrix-derivative operators is instructive because it allows us to point outsimilarities with and differences to spectral methods discussed in section 5.5.

    Consider the second-order central finite-difference approximation given byequation (5.12) on a one-dimensional grid with M points. For simplicity, wewill first assume periodic boundary conditions so that only M 1 grid pointsneed be considered. Then we can write

    12...

    i...

    M2M1

    =1

    2x

    0 1 11 0 1

    . . .. . .

    . . .

    1 0 1. . .

    . . .. . .

    1 0 11 1 0

    12...

    i...

    M2M1

    (5.59)

    where all entries that are not shown explicitly are zero. Note that the derivativematrix is antisymmetric (because it represents an odd derivative), with zeroesalong the main diagonal (because it is based on a central-difference approximationof an odd derivative), and with constant entries along the diagonals (because thegrid spacing is constant). Matrices with constant entries along diagonals arecalled Toeplitz matrices. In the case of periodic boundary conditions, the entrieson each row are given by a cyclic shift of the entries on the preceding row, andsuch matrices are called circulant.

    For non-periodic boundary conditions, one-sided approximations must be usedat the boundary points. To preserve the second-order accuracy at interior points,we can use the approximation for n = 1 and p = 2 in table 5.3 to obtain,

    12...

    i...

    M1M

    =1

    2x

    3 4 11 0 1

    . . .. . .

    . . .

    1 0 1. . .

    . . .. . .

    1 0 11 4 3

    12...

    i...

    M1M

    (5.60)

    Analogously, we can construct derivative operators corresponding to secondderivatives. For periodic boundaries, we obtain

    12

    ...i

    ...M2M1

    =1

    (x)2

    2 1 11 2 1

    . . . . . . . . .

    1 2 1. . .

    . . .. . .

    1 2 11 1 2

    12

    ...i...

    M2M1

    (5.61)

    Note that the derivative matrix is symmetric (because it represents an even deriva-tive), has non-zero entries along the main diagonal, and contains constant entriesalong the diagonals (because the grid spacing is constant). For non-periodic

    Id

  • 7/27/2019 5a Finite Difference

    15/23

    5.1. Finite-Difference Method 43

    boundary conditions, we choose a one-sided approximation for the boundarypoints which preserves the order of accuracy of the centered interior approxi-mation. Hence we choose n = 2 and p = 2 from table 5.3 and obtain

    12

    .

    ..i

    ...M1

    M

    =1

    (x)2

    2 5 4 11 2 1

    .. .

    .. .

    .. .

    1 2 1. . .

    . . .. . .

    1 2 11 4 5 2

    12.

    ..i...

    M1M

    (5.62)

    Furthermore, in general the derivative matrix is sparse because the stencilwidth of finite-difference approximations is finite. We will see in section 5.5 thatthis is not true for spectral derivative operators.

    5.1.3 Implicit Finite-Difference Approximations

    The increasing stencil width of explicit finite-difference approximations as the

    order of accuracy is increased brings two problems. First, near boundaries, one-sided stencils must be adopted farther away than with lower-order approxima-tions. Second, wider stencils include solution data that is farther removed fromthe location at which the derivative is approximated. Since the derivative is alocal quantity, including remote solution data can actually reduce the accuracyalthough the order of accuracy may be higher. For these reasons, it is commonto attempt to reduce the stencil width of finite-difference approximations.

    Implicit finite-difference approximations provide a way to obtain higher-orderaccuracy with narrower stencils than explicit approximations of the same orderof accuracy. For this reason, they are also referred to as compact finite-differencemethods. An implicit finite-difference approximation for the first derivative atpoint i can be expressed as

    sj=m

    j

    ddx

    i+j

    =

    rj=l

    ji+j + O [(x)q] (5.63)

    Comparing to equation (5.58), we see that the crucial difference is that a linearcombination of derivatives appears on the right-hand side, i.e., they appear im-plicitly. To compute derivatives using equation (5.63), we are thus required tosolve a linear system. As a result, implicit finite-difference approximations aremore costly than explicit finite-difference approximations. However, as we will seein section 6.3, implicit finite-difference approximations offer improved accuracyfor a given stencil width or order of accuracy compared to explicit finite-differenceapproximations.

    5.1.3.1 Derivation of Implicit Finite-Difference Approximations

    There are many ways in which implicit finite-difference approximations can bederived. Here we will illustrate three methods. We start by describing a methodwhich clearly demonstrates the relationship to explicit finite-difference approxi-mations and how the accuracy is improved.

    Truncation-Error Cancellation. Consider the centered difference approxima-tion to the first derivative,

    x

    i

    =i+1 i1

    2x=

    d

    dx

    i

    +(x)2

    6

    d3

    dx3

    i

    +(x)4

    120

    d5

    dx5

    i

    + . . . (5.64)

    Id

  • 7/27/2019 5a Finite Difference

    16/23

    44 Overview of Discretization Methods

    We wish to raise the order of accuracy from second to fourth without increasingthe stencil size. We can achieve this by approximating the leading term in thetruncation error with at least second-order accuracy. Because we wish to computefirst derivatives, we can approximate the third derivative appearing in the leadingterm of the truncation error as the centered second difference of centered firstdifferences. To do so, we take the first derivative of the Taylor-series expansion

    and evaluate it at i 1 to get

    d

    dx

    i1

    =d

    dx

    i

    xd2

    dx2

    i

    +(x)2

    2

    d3

    dx3

    i

    (x)3

    6

    d4

    dx4

    i

    +(x)4

    24

    d5

    dx5

    i

    + . . .

    (5.65)Hence we can approximate the third derivative as

    1

    6

    d

    dx

    i+1

    2d

    dx

    i

    +d

    dx

    i1

    =

    (x)2

    6

    d3

    dx3

    i

    +(x)4

    72

    d5

    dx5

    i

    + . . . (5.66)

    and substituting this result back into equation (5.64) gives

    1

    6 d

    dxi+1 + 4

    d

    dxi +

    d

    dxi1

    =

    i+1 i1

    2x +

    (x)4

    180

    d5

    dx5i + . . . (5.67)

    Thus by computing derivatives from

    1

    6

    x

    i+1

    + 4

    x

    i

    +

    x

    i1

    =

    i+1 i12x

    (5.68)

    we obtain fourth-order accuracy without having increased the stencil width com-pared to the second-order accurate explicit centered difference.

    Similarly, we can take the explicit finite-difference approximation to the secondderivative,

    2

    x2i

    =i+1 2i + i1

    (x)2=

    d2

    dx2i

    +(x)2

    12

    d4

    dx4i

    +(x)4

    360

    d6

    dx6i

    + . . . (5.69)

    and approximate the leading term of the truncation error as the second derivativeof second derivatives as

    1

    12

    d2

    dx2

    i+1

    2d2

    dx2

    i

    +d2

    dx2

    i1

    =

    (x)2

    12

    d4

    dx4

    i

    +(x)4

    144

    d6

    dx6

    i

    + . . . (5.70)

    and substituting back gives

    1

    12

    d2

    dx2

    i+1

    + 10d2

    dx2

    i

    +d2

    dx2

    i1

    =

    i+1 2i + i1(x)2

    +(x)4

    240

    d6

    dx6

    i

    + . . .

    (5.71)

    so that a fourth-order accurate implicit finite-difference approximation to thefourth derivative can be computed from

    1

    12

    2

    x2

    i+1

    + 102

    x2

    i

    +2

    x2

    i1

    =

    i+1 2i + i1(x)2

    (5.72)

    Taylor Series. We can follow the same procedure of using Taylor tables to deriveimplicit finite-difference approximations as outlined in section 5.1.2.1 for explicitfinite-difference approximations. Here we will illustrate the use of Taylor tables

    Id

  • 7/27/2019 5a Finite Difference

    17/23

    5.1. Finite-Difference Method 45

    Table 5.4: Taylor table for implicit centered finite-difference approx-imation for the first derivative.

    i i

    Vi

    VIIi

    IXi

    i 1 0 0 0 0

    1(i+1 + i1) 21 1(x)2 24!1(x)4 26!1(x)6 28!1(x)8

    2(i+2 +

    i2) 22 42(x)

    2 224

    4!2(x)

    4 226

    6!2(x)

    6 228

    8!2(x)

    8

    12x (i+1 i1) 1

    13!1(x)

    2 15!1(x)

    4 17!1(x)

    6 19!1(x)

    8

    24x (i+2 i2) 2

    22

    3!2(x)

    2 24

    5!2(x)

    4 26

    7!2(x)

    6 28

    9!2(x)

    8

    36x (i+3 i3) 3

    32

    3! 3(x)2 34

    5! 3(x)4 36

    7! 3(x)6 38

    9! 3(x)8

    for a slightly modified form of equation (5.63) under the assumption of a centeredapproximation on a uniform grid,

    i+1(i+1+

    i1)+2(

    i+2+

    i2) = 1

    i+1 i1

    2x

    +2i+2 i2

    4x

    +3i+3 i3

    6x(5.73)We can make the Taylor table more compact in this case by expanding the sumand difference terms appearing in equation (5.73) directly rather than each vari-able separately and only showing the columns for the odd-derivative terms. Thenthe Taylor table can be written as shown in table 5.4.

    In the table, we have drawn an additional horizontal line to separate the termsappearing on the left- and right-hand sides of equation (5.73). We thus extractthe following conditions from the Taylor table. For second-order accuracy:

    1 + 21 + 22 = 1 + 2 + 3 (5.74)

    For fourth-order accuracy: equation (5.74) and

    1 + 42 =1

    3!

    1 + 2

    22 + 323

    (5.75)

    For sixth-order accuracy: equations (5.74) and (5.75), and

    2

    4!

    1 + 2

    42

    =1

    5!

    1 + 2

    42 + 343

    (5.76)

    For eighth-order accuracy: equations (5.74) to (5.76), and

    2

    6!

    1 + 2

    62

    =1

    7!

    1 + 2

    62 + 363

    (5.77)

    For tenth-order accuracy: equations (5.74) to (5.77), and

    28!

    1 + 282

    = 19!

    1 + 282 + 383

    (5.78)

    Rather than determining the general solution, we are interested in determiningfamilies of solutions for a given stencil width and order of accuracy. By restrictingourselves to only neighboring points, we have 2 = 2 = 3 = 0, and thus onlyequations (5.74) and (5.75) can be fulfilled, giving

    1 + 21 = 1 (5.79)

    1 =1

    3!1 (5.80)

    Id

  • 7/27/2019 5a Finite Difference

    18/23

    46 Overview of Discretization Methods

    Table 5.5: Taylor table for implicit one-sided finite-difference approx-imation for the first derivative.

    1 1

    1

    1

    IV1

    1 0 1 0 0 0

    2 0 x 12(x)2 13!(x)31x1

    1x 0 0 0 0

    2x2

    2x 2

    122x

    13!2(x)

    2 14!2(x)

    3

    3x3

    3x 23

    22

    23x

    23

    3!3(x)

    2 24

    4!3(x)

    3

    4x4

    4x 34

    32

    24x

    33

    3!4(x)

    2 34

    4!4(x)

    3

    with the solution 1 =14 and 1 =

    32 and hence we again obtain equation (5.68).

    At boundaries, we will have to use either one-sided or biased approximations.For a one-sided approximation at the first grid point we replace equation (5.73)by

    1 + 2 =

    1x

    (11 + 22 + 33 + 44) (5.81)

    We produce a Taylor table in the same way as before to obtain that shown intable 5.5. As before, an additional horizontal line appears to separate the termsappearing on the left- and right-hand side of equation (5.81). Note that becausethe approximation is not centered, the function value itself and odd derivativesappear in the table. We extract the following conditions: For zeroth-order accuracy:

    0 = 1 + 2 + 3 + 4 (5.82)

    For first-order accuracy: equation (5.82) and

    1 + = 2 + 23 + 34 (5.83)

    For second-order accuracy: equations (5.82) and (5.83), and

    =1

    2

    2 + 2

    23 + 324

    (5.84)

    For third-order accuracy: equations (5.82) to (5.84), and

    1

    2! =

    1

    3!

    2 + 2

    33 + 334

    (5.85)

    For fourth-order accuracy: equations (5.82) to (5.85), and

    13!

    = 14!

    2 + 243 + 344

    (5.86)

    To get a second-order accurate approximation with 3 = 4 = 0, we thus needto solve the following system of equations,

    0 = 1 + 2 (5.87)

    1 + = 2 (5.88)

    =1

    22 (5.89)

    Id

  • 7/27/2019 5a Finite Difference

    19/23

    5.1. Finite-Difference Method 47

    Table 5.6: Taylor table for implicit centered finite-difference approx-imation for the second derivative.

    i IVi

    VIi

    VIIIi

    Xi

    i 1 0 0 0 0

    1(i+1 + i1) 21 1(x)2 24!1(x)4 26!1(x)6 28!1(x)8

    2(i+2 +

    i2) 22 42(x)

    2 224

    4!2(x)

    4 226

    6!2(x)

    6 228

    8!2(x)

    8

    1(x)2 (i+1 2i + i1) 1

    24!1(x)

    2 26!1(x)

    4 28!1(x)

    6 210!1(x)

    8

    24(x)2 (i+2 2i + i2) 2

    23

    4!2(x)

    2 25

    6!2x

    4 27

    8!2(x)

    6 29

    10!2(x)

    8

    39(x)2 (i+3 2i + i3) 3

    232

    4! 3(x)2 234

    6! 3(x)4 236

    8! 3(x)6 238

    10! 3(x)8

    The solution is = 1, 1 = 2, and 2 = 2. Therefore, a second-order accurateone-sided implicit finite-difference approximation for the first derivative is

    1 + 2 =

    2

    x

    (1 + 2) (5.90)

    We can follow the same procedure to derive implicit approximations for thesecond derivative,

    i + 1(i+1 +

    i1) + 2(

    i+2 +

    i2)

    = 1i+1 2i + i1

    (x)2+ 2

    i+2 2i + i24(x)2

    + 3i+3 2i + i3

    9(x)2(5.91)

    The corresponding Taylor table is presented in table 5.6. In the table, we haveagain drawn an additional horizontal line to separate the terms appearing onthe left- and right-hand sides of equation (5.91). We thus extract the followingconditions from the Taylor table. For second-order accuracy:

    1 + 21 + 22 = 1 + 2 + 3 (5.92)

    For fourth-order accuracy: equation (5.92) and

    1 + 42 =2

    4!

    1 + 2

    22 + 323

    (5.93)

    For sixth-order accuracy: equations (5.92) and (5.93), and

    2

    4!

    1 + 2

    42

    =2

    6!

    1 + 2

    42 + 343

    (5.94)

    For eighth-order accuracy: equations (5.92) to (5.94), and

    2

    6!

    1 + 262

    =2

    8!

    1 + 262 + 363

    (5.95)

    For tenth-order accuracy: equations (5.92) to (5.95), and

    2

    8!

    1 + 2

    82

    =2

    10!

    1 + 2

    82 + 383

    (5.96)

    Difference Calculus. The difference calculus introduced for explicit finite-difference approximations can also be used to derive implicit finite-difference ap-proximations. To illustrate this approach, we consider equation (5.48) expressed

    Id

  • 7/27/2019 5a Finite Difference

    20/23

    48 Overview of Discretization Methods

    Table 5.7: Weights andtruncation-error constantC for centered implicitfinite-difference approx-imations of derivativesof order n and order ofaccuracy p.

    j j

    n p 2 1 0 1 2 3 2 1 0 1 2 3 C

    1 4 14

    1 14

    3

    20 3

    2

    1

    180

    6 13

    1 13

    1

    9

    14

    90 14

    9

    1

    9

    2 4 110

    1 110

    6

    5

    12

    5

    6

    5

    1

    240

    6 211

    1 211

    6

    5 12

    5

    6

    5

    1

    240

    to fourth-order accuracy,

    D =0

    x

    1

    2

    6

    + O

    (x)4

    (5.97)

    which we can recast as

    D =0

    x

    1 +

    2

    6

    1+ O

    (x)4

    (5.98)

    to the same order of accuracy. When applied to a given function, the inverse

    operator appearing in equation (5.98) is to be interpreted as1 +

    2

    6

    Di =

    1

    x0i + O

    (x)4

    (5.99)

    which gives equation (5.68) on using equations (2.14) and (2.15).A selection of centered implicit finite-difference approximations are tabulated

    in table 5.7.

    5.1.3.2 Implicit Finite Differences as Differentiation Matrices

    As indicated at the beginning of this section, implicit finite differences require theinversion of a matrix to compute derivatives.

    As in section 5.1.2.2, we will first consider the case of a periodic grid. Thenequation (5.68) can be written in the following form,

    23

    16

    16

    16

    23

    16

    . . .. . .

    . . .16

    23

    16

    . . .. . .

    . . .16

    23

    16

    16

    16

    23

    12...

    i...

    M2M1

    =1

    2x

    0 1 11 0 1

    . . .. . .

    . . .

    1 0 1. . .

    . . .. . .

    1 0 11 1 0

    12...

    i...

    M2M1

    (5.100)which we can also write as

    Ay = Bx (5.101)

    Thus we require the inversion of a sparse circulant matrix to compute the deriva-tive with an implicit finite-difference approximation and periodic boundary con-ditions, i.e.,

    y = A1Bx = Dx (5.102)

    If the matrix A is tridiagonal, the efficient Thomas algorithm can be used toinvert it. An efficient algorithm also exists for pentadiagonal matrices.

    The inverse of a sparse matrix is generally dense, and multiplying a sparsematrix by a dense matrix leads to a dense matrix. So the differentiation matrix

    Id

  • 7/27/2019 5a Finite Difference

    21/23

    5.1. Finite-Difference Method 49

    D associated with implicit finite-difference approximations is generally dense, incontrast to those associated with explicit finite-difference approximations. Takingequation (5.100) as an example with M = 9, we obtain

    12345678

    =1

    56x

    0 45 12 3 0 3 12 4545 0 45 12 3 0 3 12

    12 45 0 45 12 3 0 33 12 45 0 45 12 3 0

    0 3 12 45 0 45 12 33 0 3 12 45 0 45 12

    12 3 0 3 12 45 0 4545 12 3 0 3 12 45 0

    12345678

    (5.103)

    Compare the weights with those in table 5.1 for n = 1 and p = 4. Note that theweights would be different if we had chosen a different value ofM, in contrast tothe weights of the explicit finite-difference approach.

    For non-periodic boundary conditions, we must use one-sided or biased ap-proximations near boundaries. To preserve the tridiagonal structure of the matrixA, we use a two-point approximation on the boundaries, namely equation (5.90).On the right-hand side, we also use a one-sided approximation, namely that for

    n = 1 and p = 2 in table 5.3 so that the second-order accuracy is preserved. Thuswe obtain

    1 116

    23

    16

    . . .. . .

    . . .16

    23

    16

    . . .. . .

    . . .16

    23

    16

    1 1

    12...

    i...

    M1M

    =1

    2x

    3 4 11 0 1

    . . .. . .

    . . .

    1 0 1. . .

    . . .. . .

    1 0 11 4 3

    12...

    i...

    M1M

    (5.104)The differentiation matrix D would also be dense like that for the case of periodic

    boundary conditions.At this stage, it may be noted that although the implicit finite-difference

    approximations are sometimes referred to as compact finite-difference approxi-mations, this term is somewhat misleading. The approximations are only com-pact when written in the form of equation (5.101), but not when written in theform of equation (5.102), as exemplified by the example with periodic bound-ary conditions. The global, i.e., non-compact, nature of implicit finite-differenceapproximations is the reason for their superior accuracy compared to explicitfinite-difference approximations.

    5.1.4 Multi-Dimensional Finite-Difference Approximations

    Finite-difference approximations in multiple dimensions can be derived in the

    same manner as in one dimension. Straight, i.e., non-mixed, derivatives are infact derived in exactly the same manner as in one dimension. Starting from thedefinition of the partial derivative

    x

    x0,y0

    = limx0

    (x0 + x, y0) (x0, y0)

    x(5.105)

    the finite-difference method approximates the derivative by foregoing the limitingprocess,

    x

    x0,y0

    =(x0 + x, y0) (x0, y0)

    x(5.106)

    Id

  • 7/27/2019 5a Finite Difference

    22/23

    50 Overview of Discretization Methods

    ssss

    s s s s s

    s

    sssss

    s s s s s

    sssss

    ' E

    T

    c

    E

    T

    i + 1, j

    x i

    y j

    i, j

    i, j 1

    i, j + 1

    i 1, j

    x

    s

    Figure 5.4: Finite-difference grid in two dimensions.

    On the two-dimensional Cartesian grid depicted in figure 5.4 with constant but notnecessarily equal spacings x and y, vertices can be defined by indices (i, j) suchthat the location (x0, y0) can be expressed as (ix, jy). Then equation (5.106)can be expressed as

    x

    i,j

    =i+1,j i,j

    x(5.107)

    Similarly, we have for the y-derivative,

    y

    i,j

    =i,j+1 i,j

    y(5.108)

    Equations (5.107) and (5.108) represent backward-difference approximations. Forward-and centered-difference approximations can be derived in a way similar to that inone dimension.

    For the mixed second derivative, various finite-difference approximations can

    Id

  • 7/27/2019 5a Finite Difference

    23/23

    5.1. Finite-Difference Method 51

    Derivative Finite-difference approximation TE

    2

    xy

    i,j

    1

    x

    i+1,j i+1,j1

    y

    i,j i,j1

    y

    O(x, y)

    2

    xy

    i,j

    1

    x

    i,j+1 i,j

    y

    i1,j+1 i1,j

    y

    O(x, y)

    2

    xyi,j

    1

    xi,j i,j1

    y

    i1,j i1,j1

    y

    O(x, y)

    2

    xy

    i,j

    1

    x

    i+1,j+1 i+1,j

    y

    i,j+1 i,j

    y

    O(x, y)

    2

    xy

    i,j

    1

    x

    i+1,j+1 i+1,j1

    2y

    i,j+1 i,j1

    2y

    O[x, (y)2]

    2

    xy

    i,j

    1

    x

    i,j+1 i,j1

    2y

    i1,j+1 i1,j1

    2y

    O[x, (y)2]

    2

    xy

    i,j

    1

    2x

    i+1,j+1 i+1,j1

    2y

    i1,j+1 i1,j1

    2y

    O[(x)2, (y)2]

    2

    xy

    i,j

    1

    2x

    i+1,j+1 i+1,j

    y

    i1,j+1 i1,j

    2y

    O[(x)2, y]

    2

    xy

    i,j

    1

    2x

    i+1,j i+1,j1

    y

    i1,j i1,j1

    2y

    O[(x)2, y]

    Table 5.8: Finite-difference approximationsfor mixed derivatives. Af-ter Tannehill et al. (1997,p. 53).

    be derived from the two-dimensional Taylor series,

    i+1,j+1 = i,j

    + x

    x

    i,j

    + y

    y

    i,j

    +(x)2

    2

    2

    x2

    i,j

    + xy2

    xy

    i,j

    +(y)2

    2

    2

    y2

    i,j

    + . . .

    (5.109)

    by combining function values i1,j1 in such a way that the first and straightsecond derivatives disappear. Possible approximations are shown in table 5.8.