Exercises from Finite Difference Methods for Ordinary and Partial
Total Page:16
File Type:pdf, Size:1020Kb
Exercises from Finite Difference Methods for Ordinary and Partial Differential Equations by Randall J. LeVeque SIAM, Philadelphia, 2007 http://www.amath.washington.edu/ rjl/fdmbook ∼ Under construction | more to appear. Contents Chapter 1 4 Exercise 1.1 (derivation of finite difference formula) . 4 Exercise 1.2 (use of fdstencil) . 4 Chapter 2 5 Exercise 2.1 (inverse matrix and Green's functions) . 5 Exercise 2.2 (Green's function with Neumann boundary conditions) . 5 Exercise 2.3 (solvability condition for Neumann problem) . 5 Exercise 2.4 (boundary conditions in bvp codes) . 5 Exercise 2.5 (accuracy on nonuniform grids) . 6 Exercise 2.6 (ill-posed boundary value problem) . 6 Exercise 2.7 (nonlinear pendulum) . 7 Chapter 3 8 Exercise 3.1 (code for Poisson problem) . 8 Exercise 3.2 (9-point Laplacian) . 8 Chapter 4 9 Exercise 4.1 (Convergence of SOR) . 9 Exercise 4.2 (Forward vs. backward Gauss-Seidel) . 9 Chapter 5 11 Exercise 5.1 (Uniqueness for an ODE) . 11 Exercise 5.2 (Lipschitz constant for an ODE) . 11 Exercise 5.3 (Lipschitz constant for a system of ODEs) . 11 Exercise 5.4 (Duhamel's principle) . 11 Exercise 5.5 (matrix exponential form of solution) . 11 Exercise 5.6 (matrix exponential form of solution) . 12 Exercise 5.7 (matrix exponential for a defective matrix) . 12 Exercise 5.8 (Use of ode113 and ode45) . 12 Exercise 5.9 (truncation errors) . 13 Exercise 5.10 (Derivation of Adams-Moulton) . 13 Exercise 5.11 (Characteristic polynomials) . 14 Exercise 5.12 (predictor-corrector methods) . 14 Exercise 5.13 (Order of accuracy of Runge-Kutta methods) . 14 1 Exercise 5.14 (accuracy of TR-ZBDF2) . 14 Exercise 5.15 (Embedded Runge-Kutta method) . 15 Exercise 5.16 (accuracy of a Runge-Kutta method) . 15 Exercise 5.17 (R(z) for the trapezoidal method) . 15 Exercise 5.18 (R(z) for Runge-Kutta methods) . 16 Exercise 5.19 (Pad´e approximations) . 17 Exercise 5.20 (R(z) for Runge-Kutta methods) . 17 Exercise 5.21 (starting values) . 18 Chapter 6 19 Exercise 6.1 (Lipschitz constant for a one-step method) . 19 Exercise 6.2 (Improved convergence proof for one-step methods) . 19 Exercise 6.3 (consistency and zero-stability of LMMs) . 19 Exercise 6.4 (Solving a difference equation) . 20 Exercise 6.5 (Solving a difference equation) . 20 Exercise 6.6 (Solving a difference equation) . 20 Exercise 6.7 (Convergence of backward Euler method) . 21 Exercise 6.8 (Fibonacci sequence) . 21 Chapter 7 22 Exercise 7.1 (Convergence of midpoint method) . 22 Exercise 7.2 (Example 7.10) . 22 Exercise 7.3 (stability on a kinetics problem) . 22 Exercise 7.4 (damped linear pendulum) . 22 Exercise 7.5 (fixed point iteration of implicit methods) . 23 Chapter 8 24 Exercise 8.1 (stability region of TR-BDF2) . 24 Exercise 8.2 (Stiff decay process) . 24 Exercise 8.3 (Stability region of RKC methods) . 25 Exercise 8.4 (Implicit midpoint method) . 25 Exercise 8.5 (The θ-method) . 25 Chapter 9 26 Exercise 9.1 (leapfrog for heat equation) . 26 Exercise 9.2 (codes for heat equation) . 26 Exercise 9.3 (heat equation with discontinuous data) . 27 Exercise 9.4 (Jacobi iteration as time stepping) . 27 Exercise 9.5 (Diffusion and decay) . 27 Chapter 10 29 Exercise 10.1 (One-sided and centered methods) . 29 Exercise 10.2 (Eigenvalues of A for upwind) . 30 Exercise 10.3 (skewed leapfrog) . 30 Exercise 10.4 (trapezoid method for advection) . 30 Exercise 10.5 (modified equation for Lax-Wendroff) . 31 Exercise 10.6 (modified equation for Beam-Warming) . 31 Exercise 10.7 (modified equation for trapezoidal) . 31 Exercise 10.8 (computing with Lax-Wendroff and upwind) . 31 Exercise 10.9 (computing with leapfrog) . 32 Exercise 10.10 (Lax-Richtmyer stability of leapfrog as a one-step method) . 32 Exercise 10.11 (Modified equation for Gauss-Seidel) . 34 2 Chapter 11 35 Exercise 11.1 (two-dimensional Lax-Wendroff) . 35 Exercise 11.2 (Strang splitting) . 35 Exercise 11.3 (accuracy of IMEX method) . 35 3 Chapter 1 Exercises From: Finite Difference Methods for Ordinary and Partial Differential Equations by R. J. LeVeque, SIAM, 2007. http://www.amath.washington.edu/ rjl/fdmbook ∼ Exercise 1.1 (derivation of finite difference formula) Determine the interpolating polynomial p(x) discussed in Example 1.3 and verify that eval- uation p0(x¯) gives equation (1.11). Exercise 1.2 (use of fdstencil) (a) Use the method of undetermined coefficients to set up the 5 5 Vandermonde system × 00 that would determine a fourth-order accurate finite difference approximation to u (x) based on 5 equally spaced points, 00 4 u (x) = c− u(x 2h) + c− u(x h) + c u(x) + c u(x + h) + c u(x + 2h) + O(h ): 2 − 1 − 0 1 2 (b) Compute the coefficients using the matlab code fdstencil.m available from the website, and check that they satisfy the system you determined in part (a). (c) Test this finite difference formula to approximate u00(1) for u(x) = sin(2x) with values of h from the array hvals = logspace(-1, -4, 13). Make a table of the error vs. h for several values of h and compare against the predicted error from the leading term of the expression printed by fdstencil. You may want to look at the m-file chap1example1.m for guidance on how to make such a table. Also produce a log-log plot of the absolute value of the error vs. h. You should observe the predicted accuracy for larger values of h. For smaller values, numerical cancellation in computing the linear combination of u values impacts the ac- curacy observed. 4 Chapter 2 Exercises From: Finite Difference Methods for Ordinary and Partial Differential Equations by R. J. LeVeque, SIAM, 2007. http://www.amath.washington.edu/ rjl/fdmbook ∼ Exercise 2.1 (inverse matrix and Green's functions) (a) Write out the 5 5 matrix A from (2.43) for the boundary value problem u00(x) = f(x) × with u(0) = u(1) = 0 for h = 0:25. (b) Write out the 5 5 inverse matrix A−1 explicitly for this problem. × (c) If f(x) = x, determine the discrete approximation to the solution of the boundary value problem on this grid and sketch this solution and the five Green's functions whose sum gives this solution. Exercise 2.2 (Green's function with Neumann boundary conditions) (a) Determine the Green's functions for the two-point boundary value problem u00(x) = f(x) on 0 < x < 1 with a Neumann boundary condition at x = 0 and a Dirichlet condition at x = 1, i.e, find the function G(x; x¯) solving 00 0 u (x) = δ(x x¯); u (0) = 0; u(1) = 0 − and the functions G0(x) solving 00 0 u (x) = 0; u (0) = 1; u(1) = 0 and G1(x) solving 00 0 u (x) = 0; u (0) = 0; u(1) = 1: (b) Using this as guidance, find the general formulas for the elements of the inverse of the matrix in equation (2.54). Write out the 5 5 matrices A and A−1 for the case h = 0:25. × Exercise 2.3 (solvability condition for Neumann problem) Determine the null space of the matrix AT , where A is given in equation (2.58), and verify that the condition (2.62) must hold for the linear system to have solutions. Exercise 2.4 (boundary conditions in bvp codes) (a) Modify the m-file bvp2.m so that it implements a Dirichlet boundary condition at x = a and a Neumann condition at x = b and test the modified program. (b) Make the same modification to the m-file bvp4.m, which implements a fourth order accurate method. Again test the modified program. 5 Exercise 2.5 (accuracy on nonuniform grids) 00 In Example 1.4 a 3-point approximation to u (xi) is determined based on u(xi−1); u(xi), and u(xi+1) (by translating from x1, x2, x3 to general xi−1, xi, and xi+1). It is also determined that 1 000 2 the truncation error of this approximation is (hi− hi)u (xi)+O(h ), where hi− = xi xi− 3 1 − 1 − 1 and hi = xi xi, so the approximation is only first order accurate in h if hi− and hi are +1 − 1 O(h) but hi− = hi. 1 6 The program bvp2.m is based on using this approximation at each grid point, as described in Example 2.3. Hence on a nonuniform grid the local truncation error is O(h) at each point, where h is some measure of the grid spacing (e.g., the average spacing on the grid). If we assume the method is stable, then we expect the global error to be O(h) as well as we refine the grid. (a) However, if you run bvp2.m you should observe second-order accuracy, at least provided you take a smoothly varying grid (e.g., set gridchoice = 'rtlayer' in bvp2.m). Verify this. (b) Suppose that the grid is defined by xi = X(zi) where zi = ih for i = 0; 1; : : : ; m + 1 with h = 1=(m + 1) is a uniform grid and X(z) is some smooth mapping of the interval [0; 1] to the interval [a; b]. Show that if X(z) is smooth enough, then the local truncation 2 0 error is in fact O(h ). Hint: xi xi− hX (xi). − 1 ≈ (c) What average order of accuracy is observed on a random grid? To test this, set gridchoice = 'random' in bvp2.m and increase the number of tests done, e.g., by setting mvals = round(logspace(1,3,50)); to do 50 tests for values of m between 10 and 1000.