Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Chapter 12

Finite Difference Approximations

In the previous chapter we discussed several conservation laws and demonstrated that these laws lead to partial differ-
ential equations (PDEs). In this chapter, we will show how to approximate partial derivatives using finite differences.

46 Self-Assessment
Before reading this chapter, you may wish to review...
• Taylor series expansions
• Multi-Step Methods 4
After reading this chapter you should be able to...
• determine the coefficients for finite difference approximations given a numerical stencil
• devise finite difference approximations meeting specifications on order of accuracy
Relevant self-assessment exercises: 1-5

47 Finite Difference Approximations


Recall from Chapters 1 - 4 how the multi-step methods we developed for ODEs are based on a truncated Tay-
∂U
lor series approximation for . Specifically, we can consider each multi-step method as computing U at dis-
∂t
∂ U

0 1 n
crete instances in time (t , t , . . . , t , . . .) where the derivative = Utn is approximated using a combination of
∂t n
(U n+1 , U n , U n−1 , . . .). Finite difference methods for PDEs are essentially built on the same idea, but working in space
as opposed to time. Namely, the  solution U is approximated at discrete instances in space (x0 , x1 , . . . , xi−1 , xi , xi+1 , . . . , xNx −1 , xNx )
∂ U ∂ 2U

where the spatial derivatives = Uxi , = Uxxi , . . . are approximated using a combination of (Ui , Ui±1 , Ui±2 , . . .).
∂ x i ∂ x 2 i

∆x

x0 x1 xi−1 xi xi+1 xNx −1 xNx

Fig. 18 One-dimensional structured mesh for finite difference approximations.

61
62

∂U
In the following we derive a finite difference approximation of at node xi . (Note: this is essentially the same
∂x
procedure as was used to derive the midpoint method in Chapter 3). For a differentiable function U, the derivative at
the point xi is given by:

∂ U U(xi + ∆ x) −U(xi − ∆ x)

= lim (95)
∂ x xi ∆ x→0 2∆ x

The finite difference approximation is obtained by eliminating the limiting process:

U(xi + ∆ x) −U(xi − ∆ x) Ui+1 −Ui−1


Uxi ≈ = ≡ δ2xUi . (96)
2∆ x 2∆ x
The finite difference operator δ2x is called a central difference operator. Finite difference approximations can also be
one-sided. For example, a backward difference approximation is,
1
Uxi ≈ (Ui −Ui−1 ) ≡ δx−Ui , (97)
∆x
and a forward difference approximation is,
1
Uxi ≈ (Ui+1 −Ui ) ≡ δx+Ui . (98)
∆x

Exercise 1. Write a M ATLAB function which computes the central difference approximation at nodes
x1 , x2 , . . . , xNx on the domain [0, 1] with periodic boundary conditions (i.e U0 = UNx ). The function should
have the form function dU = centraldiff(U) where U = (U1 , U2 , . . . , UNx −1 , UNx )T , and dU =
(δ2xU1 , δ2xU2 , . . . , δ2xUNx −1 , δ2xUNx )T .

Exercise 2. Write the function forwarddiff which uses a forward difference approximation with the same input.

Exercise 3. Write the function backwarddiff which uses a backward difference approximation with the same
input.

47.1 Local Truncation Error for a Derivative Approximation


In Chapter we determined the local order of accuracy of multi-step methods by computing the truncation error. The
same approach may be used to determine the order of accuracy of finite difference approximations. Suppose we use
a backwards difference, δx−Ui to approximate the first derivative, Ux at point i. The local truncation error for this
derivative approximation can be calculated using Taylor series as we have done in the past:
63

τ ≡ δx−Ui −Uxi
1
= [Ui −Ui−1 ] −Uxi
∆x   
1 1 2
= Ui − Ui − ∆ xUxi + ∆ x Uxxi + O(∆ x ) −Uxi
3
∆x 2
1
= − ∆ xUxxi + O(∆ x2 ).
2
Thus, the backwards difference approximation is a first-order accurate discretization of the derivative at node i.

Exercise 4. What is the truncation error and order of accuracy of the central difference approximation?

3 ∆ xUxxi + O(∆ x ), first-order accurate


1 2
(a)
6 ∆ x Uxxxi + O(∆ x ), first-order accurate
1 2 2
(b)
6 ∆ x Uxxxi + O(∆ x ), second-order accurate
1 2 3
(c)
3 ∆ x Uxxxi + O(∆ x ), second-order accurate
1 2 3
(d)

47.2 Finite Difference approximations for higher-order derivatives


So far we have developed several finite difference approximations for the first derivative Ux . However, we are generally
interested in solving PDEs which may also involve higher spatial derivatives (Uxx , Uxxx , . . .). As we’ve seen before
for first derivative approximations, finite difference approximations for higher derivatives may be obtained from the
definition of a derivative. For example,

∂U ∂U
∂ 2U (x + ∆ x/2) − (x − ∆ x/2)
(x) = lim ∂ x ∂x
∂ x2 ∆ x→0 ∆x
1 U(x + ∆ x) −U(x) U(x) −U(x − ∆ x)
 
= lim −
∆ x→0 ∆ x ∆x ∆x
1
= lim [U(x + ∆ x) − 2U(x) +U(x − ∆ x)] .
∆ x→0 ∆ x2

The finite difference approximation for the second order derivative is obtained eliminating the limiting process.
1
Uxxi ≈ δx2Ui ≡ (Ui+1 − 2Ui +Ui−1 ) . (99)
∆ x2
In practice, generating a finite difference approximation starting from the definition of the derivative can be quite
tedious. Instead, we may consider defining a finite difference approximation which minimizes the truncation error
using a specific set of points. Consider a generic finite difference approximation of the form:

∂ kU

1
∂ x k i
≈ ∑ α jU j
(∆ x)k j∈S
(100)

where α j are the coefficients for the finite difference approximation. S is called the stencil, and contains the list of
points used in the finite difference approximation. For example the central difference approximation, δx2 , has a 3-point
stencil using the nodal values Ui−1 , Ui and Ui+1 . Different finite difference approximations are obtained by considering
different stencils near Ui .
64

Example 1. 4-point difference approximation


We now obtain a four point finite difference approximation for the first derivative using the points Ui−1 , Ui , Ui+1 and
Ui+2 . First consider the Taylor series expansions about point Ui ,

Ui−1 = Ui − ∆ xUxi + 2 ∆ x Uxxi −


1 2
6 ∆ x Uxxxi + O(∆ x )
1 3 4

Ui = Ui
Ui+1 = Ui + ∆ xUxi + 2 ∆ x Uxxi +
1 2
6 ∆ x Uxxxi + O(∆ x )
1 3 4

Ui+2 = Ui + (2∆ x)Uxi + 2 (2∆ x) Uxxi + 6 (2∆ x) Uxxxi + O(∆ x4 )


1 2 1 3

Our finite difference approximation has the form:


1
Uxi ≈
∆x ∑ α jU j
j∈S

= ( αi−1 + αi + αi+1 + αi ) ∆1x Ui


+( −αi−1 + αi+1 + 2αi ) Uxi
+( 12 αi−1 + 2 αi+1
1
+ 2 αi ) ∆ xUxxi
4

+(− 16 αi−1 + 6 αi+1


1
+ 6 αi )∆ x Uxxxi
8 2

+O(∆ x3 )

Since we have 4 coefficients (αi−1 , αi , αi+1 , αi+2 ), we may choose these coefficients such that the terms corresponding
to Uxi sum to 1, while the terms corresponding to Ui , Uxxi and Uxxxi sum to zero. Using matrix notation:

αi−1 αi−1
        1
1 11 1 0 −3
 −1 0 1 2   αi   1   αi   − 1 
= 
 αi+1  =  1  .
which gives   2
αi+1   0 
 1 1 4 
 
2 0 2 2

− 16 0 61 86 αi+2 0 αi+2 − 16

Thus the third-order accurate difference formula using the points (Ui−1 , Ui , Ui+1 , Ui+2 ) is:

−2Ui−1 − 3Ui + 6Ui+1 −Ui+2


Uxi ≈
6∆ x

Exercise 5. Give the coefficients of the finite difference approximation for Uxxxi using the 5-point stencil
(Ui−2 , Ui−1 , Ui , Ui+1 , Ui+2 ).

Exercise 6. What is the order of accuracy for this finite difference approximation?

47.3 Finite Difference Approximations in 2D


We can easily extend the concept of finite difference approximations to multiple spatial dimensions. In this case we
represent the solution on a structured spatial mesh as shown in Figure 19.
Using Ui, j to denote the value of U at node (i, j) our central derivative approximations for the first derivatives are:
65

Fig. 19 Two-dimensional structured mesh for finite difference approximations.

∂ U

Ui+1, j −Ui−1, j
≈ ≡ δ2xUi, j .
∂ x i, j 2∆ x
∂ U

Ui, j+1 −Ui, j−1
≈ ≡ δ2yUi, j .
∂y
i, j 2∆ y

In general, finite difference approximation will involve a stencil of points surrounding Ui, j .

You might also like