Finite Difference Methods for Solving Differential
Total Page:16
File Type:pdf, Size:1020Kb
FINITE DIFFERENCE METHODS FOR SOLVING DIFFERENTIAL EQUATIONS I-Liang Chern Department of Mathematics National Taiwan University May 16, 2013 2 Contents 1 Introduction 3 1.1 Finite Difference Approximation . ........ 3 1.2 Basic Numerical Methods for Ordinary Differential Equations ........... 5 1.3 Runge-Kuttamethods..... ..... ...... ..... ...... ... ... 8 1.4 Multistepmethods ................................ 10 1.5 Linear difference equation . ...... 14 1.6 Stabilityanalysis ............................... 17 1.6.1 ZeroStability................................. 18 2 Finite Difference Methods for Linear Parabolic Equations 23 2.1 Finite Difference Methods for the Heat Equation . ........... 23 2.1.1 Some discretization methods . 23 2.1.2 Stability and Convergence for the Forward Euler method.......... 25 2.2 L2 Stability – von Neumann Analysis . 26 2.3 Energymethod .................................... 28 2.4 Stability Analysis for Montone Operators– Entropy Estimates ........... 29 2.5 Entropy estimate for backward Euler method . ......... 30 2.6 ExistenceTheory ................................. 32 2.6.1 Existence via forward Euler method . ..... 32 2.6.2 A Sharper Energy Estimate for backward Euler method . ......... 33 2.7 Relaxationoferrors.............................. 34 2.8 BoundaryConditions ..... ..... ...... ..... ...... ... 36 2.8.1 Dirichlet boundary condition . ..... 36 2.8.2 Neumann boundary condition . 37 2.9 The discrete Laplacian and its inversion . .......... 38 2.9.1 Dirichlet boundary condition . ..... 38 3 Finite Difference Methods for Linear elliptic Equations 41 3.1 Discrete Laplacian in two dimensions . ........ 41 3.1.1 Discretization methods . 41 3.1.2 The 9-point discrete Laplacian . ..... 42 3.2 Stability of the discrete Laplacian . ......... 43 3 4 CONTENTS 3.2.1 Fouriermethod ................................ 43 3.2.2 Energymethod ................................ 44 4 Finite Difference Theory For Linear Hyperbolic Equations 47 4.1 A review of smooth theory of linear hyperbolic equations .............. 47 4.1.1 Linear advection equation . 47 4.1.2 Linear systems of hyperbolic equations . ....... 48 4.2 Finite difference methods for linear advection equation ............... 51 4.2.1 Designtechniques .............................. 51 4.2.2 Courant-Friedrichs-Levy condition . ....... 53 4.2.3 Consistency and Truncation Errors . ...... 54 4.2.4 Lax’s equivalence theorem . 55 4.2.5 Stabilityanalysis ..... ..... ...... ..... ...... .. 55 4.2.6 Modifiedequation .............................. 58 4.3 Finite difference schemes for linear hyperbolic system with constant coefficients . 61 4.3.1 Some design techniques . 61 4.3.2 Stabilityanalysis ..... ..... ...... ..... ...... .. 62 4.4 Finite difference methods for linear systems with variable coefficients . 64 5 Scalar Conservation Laws 67 5.1 Physicalmodels .................................. 67 5.1.1 Trafficflowmodel .............................. 67 5.1.2 Burgers’equation..... ..... ...... ..... ...... ... 68 5.1.3 Twophaseflow................................ 69 5.2 Basictheory..................................... 69 5.2.1 Riemannproblem............................... 70 5.2.2 Entropyconditions .... ..... ...... ..... ...... ... 71 5.2.3 Rieman problem for nonconvex fluxes . 74 5.3 Uniqueness and Existence . 74 6 Finite Difference Schemes For Scalar Conservation Laws 77 6.1 Majorproblems................................... 77 6.2 Conservativeschemes. 78 6.3 Entropy and Monotone schemes . 80 7 Finite Difference Methods for Hyperbolic Conservation Laws 85 7.1 Fluxsplittingmethods . 86 7.1.1 Total Variation Diminishing (TVD) . ..... 86 7.1.2 Other Examples for φ(θ) ........................... 88 7.1.3 Extensions .................................. 89 7.2 HighOrderGodunovMethods . 90 7.2.1 Piecewise-constant reconstruction . ........ 91 7.2.2 piecewise-linear reconstruction . ........ 94 CONTENTS 1 7.3 Multidimension .................................. 97 7.3.1 SplittingMethod ............................... 98 7.3.2 UnsplittingMethods . 99 8 Systems of Hyperbolic Conservation Laws 101 8.1 GeneralTheory ................................... 101 8.1.1 RarefactionWaves .............................. 102 8.1.2 ShockWaves ................................. 102 8.1.3 Contact Discontinuity (Linear Wave) . 105 8.2 PhysicalExamples ................................ 106 8.2.1 Gasdynamics................................. 106 8.2.2 Riemann Problem of Gas Dynamics . 110 9 Kinetic Theory and Kinetic Schemes 117 9.1 KineticTheoryofGases ... ..... ...... ..... ...... ... 117 9.2 Kineticscheme ................................... 117 2 CONTENTS Chapter 1 Introduction The goal of this course is to provide numerical analysis background for finite difference methods for solving partial differential equations. The focuses are the stability and convergence theory. The partial differential equations to be discussed include parabolic equations, • elliptic equations, • hyperbolic conservation laws. • 1.1 Finite Difference Approximation Our goal is to appriximate differential operators by finite difference operators. How to perform approximation? What is the error so produced? We shall assume the underlying function u : R R → is smooth. Let us define the following finite difference operators: u(x+h) u(x) Forward difference: D u(x) := − , • + h u(x) u(x h) Backward difference: D u(x) := − − , • − h u(x+h) u(x h) Centered difference: D u(x) := − − . • 0 2h Here, h is called the mesh size. By Taylor expansion, we can get u (x)= D u(x)+ O(h), • ′ + u′(x)= D u(x)+ O(h), • − u (x)= D u(x)+ O(h2). • ′ 0 We can also approximate u′(x) by other finite difference operators with higher order errors. For example, 3 u′(x)= D3u(x)+ O(h ), 3 4 CHAPTER 1. INTRODUCTION where 1 D u(x)= (2u(x + h) + 3u(x) 6u(x h)+ u(x 2h)) . 3 6h − − − These formulae can be derived by performing Taylor expansion of u at x. For instance, we expand h2 h3 u(x + h) = u(x)+ u′(x)h + u′′(x)+ u′′′(x)+ 2 3! · · · h2 h3 u(x h) = u(x) u′(x)h + u′′(x) u′′′(x)+ . − − 2 − 3! · · · Substracting these two equations yields 2h3 u(x + h) u(x h) = 2u′(x)h + u′′′(x)+ . − − 3! · · · This gives 2 h 2 u′(x)= D u(x) u′′′(x)+ = D u(x)+ O(h ). 0 − 3! · · · 0 In general, we can derive finite difference approximation for u(k) at specific point x by the values of u at some nearby stencil points x , j = 0, ..., n with n k. That is, j ≥ n (k) p k+1 u (x)= cju(xj)+ O(h − ) Xj=0 for some p as larger as possible. Here, the mesh size h denotes max x x . As we shall see {| i − j|} later that we can choose p = n. To find the coefficients cj, j = 0, ..., n, we make Taylor expansion of u(xj) about the point x: p 1 u(x )= (x x)iu(i)(x)+ O(hp+1). j i! j − Xi=0 We plug this expansion formula of u(xj) into the finite difference approximation formula for u(k)(x): n p (k) 1 i (i) p k+1 u (x)= c (x x) u (x)+ O(h − ). j i! j − Xj=0 Xi=0 Comparing both sides, we obtain n 1 (x x)i 1 if i = k j − c = , for i = 0, ..., p i! hi j 0 otherwise Xj=0 There are p + 1 equations here, it is natural to choose p = n to match the n + 1 unknowns. This is a n n Vandermonde system. It is nonsingular if x are different. The matlab code fdcoeffV(k,xbar,x) × i can be used to compute these coefficients. Reference: Randy LeVeque’s book and his Matlab code. 1.2. BASIC NUMERICAL METHODS FOR ORDINARY DIFFERENTIAL EQUATIONS 5 In the case of uniform grid, using central finite differencing, we can get high order approxima- tion. For instance, let x = jh, where j Z. Let u = u(x ). Then j ∈ j j u1 u 1 2 u′(0) = − − + O(h ) h u1 2u0 + u 1 2 u′′(0) = − − + O(h ) h2 (3) 1 2 u = (u2 2u1 + 2u0 2u 1 + u 2)+ O(h ). 2h3 − − − − Homeworks. (k) 1. Consider xi = ih, i = 0, ..., n. Let x¯ = xm. Find the coefficients ci for u (¯x) and the coefficient of the leading truncation error for the following cases: k = 1, n = 2, 3, m = 0, 1, 2, 3. • k = 2, n = 2, m = 0, 1, 2. • 1.2 Basic Numerical Methods for Ordinary Differential Equations The basic assumption to design numerical algorithm for ordinary differential equations is the smooth- ness of the solutions, which is in general valid provided the coefficients are also smooth. Basic designning techniques include numerical interpolation, numerical integration, and finite difference approximation. Euler method Euler method is the simplest numerical integrator for ODEs. The ODE y′ = f(t,y) (2.1) is discretized by yn+1 = yn + kf(tn,yn). (2.2) Here, k is time step size of the discretization. This method is called the forward Euler method. It simply replace dy/dt(tn) by the forward finite difference (yn+1 yn)/k. By Taylor expansion, the − local truncation error is n+1 n n n y(t ) y(t ) τ := y′(t ) − = O(k) − k Let en := yn y(tn) be the true error. − Theorem 2.1. Assume f C1 and suppose the solution y = f(t,y) with y(0) = y exists on ∈ ′ 0 [0, T ]. Then the Euler method converges at any t [0, T ]. In fact, the true error en has the following estimate: ∈ eλt en O(k) 0, as n . (2.3) | |≤ λ → →∞ Here, λ = max ∂f/∂y and nk = t. | | 6 CHAPTER 1. INTRODUCTION Proof. From the regularity of the solution, we have y C2[0, T ] and ∈ y(tn+1)= y(tn)+ kf(tn,y(tn)) + kτ n. (2.4) Taking difference of (2.2) and (2.4), we obtain en+1 en + k f(tn,yn) f(tn,y(tn)) + k τ n | | ≤ | | | − | | | (1 + kλ) en + k τ n . ≤ | | | | where f(t,x) f(t,y) λ x y . | − |≤ | − | The finite difference inequality has a fundamental solution Gn = (1+ λk)n, which is positive n 1 provided k is small. Multiplying above equation by (1 + λk)− − , we obtain m+1 m 1 m m m 1 m e G− − e G− + kG− − τ . | | ≤ | | | | Summing in m from m = 0 to n 1, we get − n 1 n 1 n − n m 1 m − m 2 e G − − k τ G O(k ) | | ≤ | |≤ m=0 m=0 X X Gn 1 Gn eλt = − O(k2) O(k) O(k), G 1 ≤ λ ≤ λ − where t = nk and we have used (1 + λk)n eλt.