Finite difference methods Siltanen/Railo/Kaarnioja Spring 8 Applications of matrix computations Applications of matrix computations Finite difference methods Spring 8 /
Introduction Finite difference methods (FDM) are numerical methods for solving (partial) differential equations, where (partial) derivatives are approximated by finite differences. Example For < h, we have the approximations (i) f f (x + h) f (x) (x), h (ii) f f (x) f (x h) (x), h (iii) f f (x + h) f (x h) (x), and h (iv) f f (x + h) f (x) + f (x h) (x) h. Applications of matrix computations Finite difference methods Spring 8 /
Let a = x < x < < x n = b be a uniform partition of the interval [a, b], where x k = a + hk, k {,,..., n}, and h = (b a)/n. The formulae on the previous page can be used to derive discrete approximations for (i) [f (x ), f (x ),..., f (x n )] T = Af, (ii) [f (x ), f (x ),..., f (x n )] T = Bf, (iii) [f (x ), f (x ),..., f (x n )] T = Cf, and (iv) [f (x ), f (x ),..., f (x n )] T = Df using the point values f = [f (x ), f (x ),..., f (x n )] T. Proof. Homework! :) Note: By using a suitable quadrature rule (e.g., the left-, mid-, or right-point rule or the trapezoidal rule), one can obtain a discretized approximation for the antiderivative as well! Applications of matrix computations Finite difference methods Spring 8 3 /
Finite difference methods for the equation y (t) = f (t, y(t)) Applications of matrix computations Finite difference methods Spring 8 /
Let s consider the IVP { y (t) = f (t, y(t)), t, y() = y. To ensure (local) unique solvability, it is assumed that f is continuous and that f (t, ) is Lipschitz-continuous [Picard Lindelöf theorem]. How do we get rid of the derivative? By integration: t y(t) = y + f (τ, y(τ)) dτ. Bad news: We have just turned our differential equation into an integral equation, which we still need to solve for y(t). Good news: We know how to do numerical integration! Applications of matrix computations Finite difference methods Spring 8 /
We are interested in solving the IVP for t [, T ], T >. Let = t < t < < t n = T be an equispaced partition of the interval [, T ], t k = hk, k {,,..., n}, and h = T /n. Let us denote y(t k ) = y k. We can recast the integral equation on the previous page as y k+ = y k + t k+ t k f (t, y(t)) dt for k =,,..., n. Let s try different quadratures for approximating the integral above! Remark. We omit the detailed error analysis of the resulting formulae and focus on some heuristics of the solution methods. Applications of matrix computations Finite difference methods Spring 8 6 /
One-point Riemann sum approximations over [t k, t k+ ] Left-point rule: y k+ y k + hf (t k, y k ). (Euler s method) Right-point rule: y k+ y k + hf (t k+, y k+ ). (Implicit Euler s method) Midpoint rule: y k+ y k + hf (t k + h, y k + h f (t k, y k )). (Runge Kutta method) Applications of matrix computations Finite difference methods Spring 8 7 /
Two-point trapezoidal rule over [t k, t k+ ] y k+ y k + h (f (t k, y k ) + f (t k+, y k+ )) y k + h f (t k, y k ) + h f (t k + h, y k + hf (t k, y k )). Applications of matrix computations Finite difference methods Spring 8 8 /
Two-point trapezoidal rule over [t k, t k+ ] y k+ y k + h (f (t k, y k ) + f (t k+, y k+ )) y k + h f (t k, y k ) + h f (t k + h, y k + hf (t k, y k )). Applications of matrix computations Finite difference methods Spring 8 8 /
Two-point trapezoidal rule over [t k, t k+ ] k = hf (t k, y k ), y k+ y k + k + h f (t k + h, y k + k ). Applications of matrix computations Finite difference methods Spring 8 8 /
Two-point trapezoidal rule over [t k, t k+ ] k = hf (t k, y k ), y k+ y k + k + h f (t k + h, y k + k ). Applications of matrix computations Finite difference methods Spring 8 8 /
Two-point trapezoidal rule over [t k, t k+ ] k = hf (t k, y k ), k = hf (t k + h, y k + k ), y k+ y k + k + k. This is the second order Runge Kutta method (RK). Applications of matrix computations Finite difference methods Spring 8 8 /
There is a similar relationship between the famous fourth order Runge Kutta method (RK) and Simpson s rule: k = hf (t k, y k ), k = hf (t k + h, y k + k ), k 3 = hf (t k + h, y k + k ), k = hf (t k+, y k + k 3 ), y k+ y k + 6 (k + k + k 3 + k ). The RK rule can be derived by first applying Simpson s rule and then balancing the midstep (here y k+/ = y(t k+/ ) and t k+/ = t k + h/) f (t k+/, y k+/ ) = f (t k+/, y k+/ ) + f (t k+/, y k+/ ) by using two different methods: f (t k+/, y k+/ ) f (t k + h, y k + k ), f (t k+/, y k+/ ) f (t k + h, y k + k ). (left-point rule) (right-point rule) Applications of matrix computations Finite difference methods Spring 8 9 /
In summary There exists a wide range of literature on FD methods for first order IVPs and the theory extends nicely to first order systems of ODEs as well. The examples on pg. 7 highlight a couple of canonical cases: (A) Explicit methods, (B) Implicit methods. While simple and intuitive, explicit methods are never unconditionally stable. For example, when working with [stiff equations], certain implicit methods are able to capture the asymptotics of the solution regardless of the step size. Another class of FD methods is represented by Runge Kutta methods, where the FD solution is adjusted based on point evaluations at additional intermediate points between the discretization mesh. Applications of matrix computations Finite difference methods Spring 8 /
For an introduction into the approximation and stability theory of first order FD methods, I highly recommend the monograph [Griffiths and Higham]! Applications of matrix computations Finite difference methods Spring 8 /
Finite difference methods for Poisson s equation u = f Applications of matrix computations Finite difference methods Spring 8 /
Let denote the Laplacian. u(x, y) = u(x, y) + u(x, y) x y In the following, we discuss the solution of Poisson s equation u = f in a bounded domain Ω R with the Dirichlet boundary condition u = g on Ω. where f and g are given functions. Applications of matrix computations Finite difference methods Spring 8 3 /
We need to discretize Poisson s equation in order to find a suitable matrix approximation Au = m, which we can then solve numerically. We can obtain an approximate formula for u near (x, y) by developing Taylor expansions of u(x, y) with respect to x and y variables, respectively. Assuming sufficient smoothness, we obtain u(x + h, y) = u(x, y) + h x u(x, y) + h x u(x, y) + 6 h3 3 x u(x, y) + O(h ), u(x h, y) = u(x, y) h x u(x, y) + h x u(x, y) 6 h3 3 x u(x, y) + O(h ). The sum of these is u(x + h, y) + u(x h, y) = u(x, y) + h x u(x, y) + O(h ) Applications of matrix computations Finite difference methods Spring 8 /
Developing the Taylor expansion w.r.t. the x variable yielded u(x + h, y) + u(x h, y) = u(x, y) + h x u(x, y) + O(h ). () Proceeding analogously with the other component: u(x, y + h) = u(x, y) + h y u(x, y) + h y u(x, y) + 6 h3 3 y u(x, y) + O(h ), u(x, y h) = u(x, y) h y u(x, y) + h y u(x, y) 6 h3 3 y u(x, y) + O(h ) u(x, y + h) + u(x, y h) = u(x, y) + h y u(x, y) + O(h ). () By summing () and () together, we obtain u(x + h, y) + u(x h, y) + u(x, y + h) + u(x, y h) = u(x, y) + h u(x, y) + O(h ) u(x, y) = u(x + h, y) + u(x h, y) + u(x, y + h) + u(x, y h) u(x, y) h + O(h ). Applications of matrix computations Finite difference methods Spring 8 /
Five-point stencil (quincunx): u (x,y+h) u (x-h,y) u (x,y) u (x+h,y) u (x,y-h) u(x, y) u(x + h, y) + u(x h, y) + u(x, y + h) + u(x, y h) u(x, y) h Applications of matrix computations Finite difference methods Spring 8 6 /
Recovering missing pixels During the lecture, we discussed the example presented in Poisson FD v.pdf (see course page). Figure: Image by Samuli Siltanen. Applications of matrix computations Finite difference methods Spring 8 7 /
For a given (polygonal) computational domain, we could attempt to create a quincunx mesh where, for each individual mesh element (x, y), the neighbouring coordinates (x ± h, y) and (x, y ± h) are either Other mesh elements, Boundary points. 3 3 3 3 Applications of matrix computations Finite difference methods Spring 8 8 /
6-6 - - -3 - - -3 3 3 6 6 unknowns u(x i) boundary values g i Example Let s solve the Dirichlet problem { u = in Ω, u Ω = g on Ω, where the computational domain Ω is the L-shaped domain on the left, the discretization mesh is denoted by black dots, and the boundary values of g are given in red at the discretization nodes lying on the boundary. Applications of matrix computations Finite difference methods Spring 8 9 /
Let s give a numbering to the unknowns! 6-6 - - -3 6-6 - - -3 - - - -3 3 - -3 3 6 3 3 6 6 7 8 9 3 6 3 6 unknowns u(xi) boundary values gi 6 Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 6 3 u(x ) u(x ) + u(x 3 ) u(x ) h [ ] u(x ) h u(x ) = h u(x 3 ) 6 Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 6 3 u(x ) u(x ) + u(x ) u(x ) h [ ] u(x ) u(x ) h u(x 3 ) = [ ] h 6 u(x ) 6 Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - 3-3 6 3 7 8 9 3 6 3 6 6 u(x 3 ) u(x )+u(x )+u(x ) u(x 3 ) h u(x ) u(x ) h u(x 3 ) u(x ) = u(x ) h 6 Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m := [, 6,,,,,,,,,,,,,, ] T u(x ) h A. = h m u(x 6 ) =: A Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m := [, 6,,, 3,,,,,,,,,,, ] T u(x ) h A. = h m u(x 6 ) =: A Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m := [, 6,,, 3,,,,,,,,,,, ] T u(x ) h A. = h m u(x 6 ) =: A Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m := [, 6,,, 3,,,,,,,,,,, ] T u(x ) h A. = h m u(x 6 ) =: A Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m := [, 6,,, 3,,,,,,,,,,, ] T u(x ) h A. = h m u(x 6 ) =: A Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m := [, 6,,, 3,,,,,,,,,,, ] T u(x ) h A. = h m u(x 6 ) =: A Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 =: A m := [, 6,,, 3,,,,,,,,,,, ] T u(x ) h A. = h m u(x 6 ) Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 =: A m := [, 6,,, 3,,,,,, 6,,,,, ] T u(x ) h A. = h m u(x 6 ) Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 =: A m := [, 6,,, 3,,,,,, 6,,,,, ] T u(x ) h A. = h m u(x 6 ) Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m := [, 6,,, 3,,,,,, 6,,,,, ] T u(x ) h A. = h m u(x 6 ) =: A Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m := [, 6,,, 3,,,,,, 6,,, 3,, ] T u(x ) h A. = h m u(x 6 ) =: A Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m := =: A [, 6,,, 3,,,,,, 6,,, 3,, ] T u(x ) h A. = h m u(x 6 ) Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m := =: A [, 6,,, 3,,,,,, 6,,, 3,, ] T u(x ) h A. = h m u(x 6 ) Applications of matrix computations Finite difference methods Spring 8 /
6-6 - - -3 - - -3 3 6 3 7 8 9 3 6 3 6 6 m = = A [, 6,,, 3,,,,,, 6,,, 3,, ] T u(x ) h A. = h m u(x 6 ) Applications of matrix computations Finite difference methods Spring 8 /
Numerical solution: >> A\m should give [u(x ),..., u(x 6 )] T = [, 3, 3,,,,,,,, 3,,,, 3, ] T. Compare this with the analytical solution u(x, y) = x y. (They are exactly the same!) Applications of matrix computations Finite difference methods Spring 8 /
Numerical experiment Let s return to the isospectral drums discussed earlier during the course. 3 3 3 3 Figure: Isospectral drum shapes in D [Gordon, Webb, and Wolpert]. Two drums with clamped boundaries give the same sound if they have the same set of (Dirichlet) eigenvalues λ satisfying u = λu in D, u D =, D R bounded domain. Applications of matrix computations Finite difference methods Spring 8 3 /
The quincunx pattern has extremely important applications in statistics as well! https://www.youtube.com/watch?v=ausktk9enzg Applications of matrix computations Finite difference methods Spring 8 /
Bibliography C. Gordon, D. Webb, and S. Wolpert. Isospectral plane domains and surfaces via Riemannian orbifolds. Inventiones Mathematicae ():, 99. DOI:.7/BF33 D. F. Griffiths and D. J. Higham. Numerical Methods for Ordinary Differential Equations. Springer,. Applications of matrix computations Finite difference methods Spring 8 /