Professional Documents
Culture Documents
Chapter12 PDF
Chapter12 PDF
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
∆x
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
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.
τ ≡ δ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?
∂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
Ui = Ui
Ui+1 = Ui + ∆ xUxi + 2 ∆ x Uxxi +
1 2
6 ∆ x Uxxxi + O(∆ x )
1 3 4
+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:
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?
∂ 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 .