Finite Difference Method
Total Page:16
File Type:pdf, Size:1020Kb
Chapter 8 Finite Difference Method 8.1 2nd order linear p.d.e. in two variables General 2nd order linear p.d.e. in two variables is given in the following form: L[u]= Auxx + 2Buxy + Cuyy + Dux + Euy + F u = G According to the relations between coefficients, the p.d.es are classified into 3 categories, namely, elliptic if AC − B2 > 0 i.e., A, C has the same sign hyperbolic if AC − B2 < 0 parabolic if AC − B = 0 Furthermore, if the coefficients A, B and C are constant, it can be written as ∂ ∂ A B ∂u [ , ] ∂x + Du + Eu + F u = G. ∂x ∂y ∂u x y "B C#" ∂y # Auxiliary condition B.C. Interface Cond I.C. we say “well posed” if a solution exists. There are basically two class of method to discretize it, 1 2 CHAPTER 8. FINITE DIFFERENCE METHOD (1) Finite Difference method (2) Finite Element method 8.2 Finite difference operator n Let u(x) be a function defined on Ω ⊂ R . Let Ui,j be the function defined over discrete domain {(xi,yj)} such that Ui,j = u(xi,yj). Such functions are called grid functions. We introduce difference operators on the grid functions. + Ui+1 − Ui δ Ui = , forward difference hi+1 − Ui − Ui−1 δ Ui = , backward difference hi 0 Ui+1 − Ui−1 δ Ui = , central difference hi + hi+1 + − 2 2(δ − δ ) δ Ui = , central 2nd difference hi + hi+1 Example 8.2.1. Consider the following second order differential equation : −u′′(x)= f(x), u(a)= c, u(b)= d. Given a mesh a = x0 <x1 < · · · <xN = b, ∆xi = xi+1 − xi = h, we have U − − 2U + U − i 1 i i+1 = f = f(x ), i = 1, · · · N − 1,U = c, U = d h2 i i 0 N which determines Ui uniquely. We obtain an (N−1)×(N−1) matrix equations. 2 −1 U1 f1 c −1 2 −1 · · 0 . · = h2 · + 0 −1 2 −1 · · 0 −1 2 U f d N−1 N−1 h h Above equation can be written as LhU = F , called a difference equation for a given differential equation. 8.2. FINITE DIFFERENCE OPERATOR 3 Exercise 8.2.2. Write down a matrix equation for the same problem with second boundary condition changed to the normal derivative condition at b, i.e, u′(b)= d. If one uses first order difference for derivative, we lose accuracy. We need an extra equation in this case. There are several choices: (1) Use first order backward difference scheme U − U − 1 n 1 = d h and append this to the last eq.( first order) (2) Use central difference equation by assuming a fictitious point UN+1 and assume the D.E. holds at the end point: Use 1 − (U − − 2U + U ) = f(1) (8.1) h2 N 1 N N+1 1 (U − U − ) = b. (8.2) 2h N+1 N 1 Solve the last eq. and substitute into first eq. 1 b 1 (U − U − )= − + f(1). (8.3) 2h N N 1 h 2 ′ h Eq. 8.3 can be viewed as centered difference approximation to u (xn − 2 ) and rhs as the first two terms of Taylor expansion h h u′(x − )= u′(x ) − u′′(x )+ · · · n 2 n 2 n (3) Use − − u′ − u′ d − uN uN 1 u′′ ≈ N N−1 = h = −f(1) h h so that u − u − N N 1 = d + hf(1). h This is interpreted as using Taylor series of u′(1 − h)= u′(1) + hf(1) = ′ ′′ h u (1)−hu (1) But lhs is centered difference to u(1− 2 ). So not consistent. (4) Approximate u′(1) by higher order scheme such as u − − 4u − + 3u N 2 N 1 N = b. h 4 CHAPTER 8. FINITE DIFFERENCE METHOD Example 8.2.3 (Heat equation). We consider ut = σuxx, for 0 <x< 1, 0 <t<T u(t, 0) = u(t, 1) = 0 u(0,x) = g(x), g(0) = g(1) = 0 T Let xi = ih, i = 0, · · · , N, ∆x = 1/N and tn = n∆t, ∆t = J . Then we have the following difference scheme U n+1 − U n U n − 2U n + U n i i = σ i−1 i i+1 , ∆t ∆x2 n for i = 1, 2, · · · ,N − 1 and n = 1, 2, · · · , M − 1 where Ui ≈ u(ti,xn). From the boundary condition and initial condition we have 0 n n Ui = g(xi),U0 = 0,UN = 0. σ∆t U n+1 = U n + U n − 2U n + U n . i i ∆x2 i−1 i i+1 In vector notation σ∆t U n+1 = U n − AU n h h ∆x2 h where A is the same matrix as in example 1. If n = 0, right hand side is known. Thus n ∆t n T U = (I − σ A) G, G = (g(x ), · · · , g(x − )) . h ∆x2 1 N 1 This is called forward Euler or explicit scheme. If we change the right hand side to n+1 n n+1 n+1 n+1 Ui − Ui Ui−1 − 2Ui + Ui+1 = σ 2 ∆t " ∆x # σ∆t U n+1 = U n + U n+1 − 2U n+1 + U n+1 . i i ∆x2 i−1 i i+1 ∆t n n T (I + σ A) U = G, G = (g(x ), · · · , g(x − )) . ∆x2 h 1 N 1 This is called backward Euler or implicit scheme. 8.2. FINITE DIFFERENCE OPERATOR 5 8.2.1 Error of difference operator 2 For u ∈ C , use the Taylor expansion about xi h2 u = u(x + h )= u(x )+ h u′(x )+ i u′′(ξ), ξ ∈ (x ,x ) i+1 i i i i i 2 i i+1 ui+1 − ui ′ hi ′′ ∴ − u (xi) = u (ξ). hi 2 Expand about xi+1, h u = u − h u′(x )+ i u′′(θ). i i+1 i i 2 These are first order accurate. To derive a second order scheme, expand about xi+1/2, h 1 h 1 h u = u + i u′(x )+ ( i )2u′′(x )+ ( i )3u(3)(ξ) i+1 i+1/2 2 i+1/2 2 2 i+1/2 6 2 h 1 h 1 h u = u − i u′(x )+ ( i )2u′′(x ) − ( i )3u(3)(ξ). i i+1/2 2 i+1/2 2 2 i+1/2 6 2 Subtracting, ui+1 − ui ′ 2 = u (xi+1/2)+ O(hi ). hi ′ Thus we obtain a second order approximation to u (xi+1/2). By translation, we have ui+1 − ui−1 ′ 2 − u (xi)= O(hi /6) if hi = hi+1. 2hi Assume hi = hi+1 and we substitute the solution of differential equation into the difference equation. Using −u′′ = f we obtain (−u − + 2u − u ) i 1 i i+1 − f(x ) h2 i 1 h2 h3 h4 = (−u + hu′ − u′′ + u(3) − u(4)(θ ) + 2u ) h2 i i 2 i 6 24 1 i 1 h2 h3 h4 + (−u − hu′ − u′′ − u(3) − u(4)(θ )) − f(x ) h2 i i 2 i 6 24 2 i h2 = −u′′ − f(x ) − (u(4)(θ )+ u(4)(θ )) truncation error i i 24 1 2 h2 = max |u(4)|. 12 h We let τh = Lhu − F and call it the truncation error(discretization 6 CHAPTER 8. FINITE DIFFERENCE METHOD error). Definition 8.2.4. We say a difference scheme is consistent if the truncation error approaches zero as h approaches zero, in other words, if Lhu − f → 0 in some norm. Truncation error measures how well the difference equation approximates the differential equation. But it does not measure the actual error in the solution. Use of different quadrature for f. Instead of f(xi) we can use 1 5 µ0 [f(x − ) + 10f(x )+ f(x )] = f(x )+ f(x ) 12 i 1 i i+1 6 i 6 i 2 where µ0f(xi) is the average of f which is f(xi)+ O(h ). H.W Let −u′′ = f. Show the following for uniform grid −ui−1 + 2ui − ui−1 1 4 (6) = [f(x − ) + 10f(x )+ f(x )] + Ch max |u (x)|. h2 12 i 1 i i+1 Definition 8.2.5. Lh is said to be stable if h h kUhk≤ CkLhU k≤ CkF k for all h> 0 h h h where U is the solution of the difference equation, LhU = F . Also note −1 that Lh is stable if and only if Lh is bounded. Definition 8.2.6. A finite difference scheme is said to converge if kU h − uk→ 0 as h → 0. kU h − uk is called a discretization error. Theorem 8.2.7 (P. Lax). Given a consistent scheme, stability is equivalent to convergence. h h h Proof. Assume stability. From Lhu − f = τ ,LhU − F = 0, we have Lh(u − U h)= τ h. Thus, h h h ku − U k≤ CkLh(u − U )k = Ckτ k→ 0. Hence the scheme converges. Obviously a convergent scheme must be stable. 8.3. ELLIPTIC EQUATION 7 From the theory of p.d.e, we know kuk≤ Ckfk. Hence kU hk ≤ kU h − uk + kuk≤ O(τ h)+ Ckfk≤ Ckfk≤ CkF hk. 8.3 Elliptic equation 8.3.1 Basic finite difference method for elliptic equation In this chapter, we only consider finite difference method. First consider the following elliptic problem:(Dirichlet problem by Finite Difference Method) −∆u = f in Ω u = g on ∂Ω (1) Approx. D.E. −(uxx + uyy)= f at each interior mesh pt.