Author: | Hans Petter Langtangen |
---|---|
Date: | Dec 14, 2013 |
Note: PRELIMINARY VERSION
Finite difference methods for partial differential equations (PDEs) employ a range of concepts and tools that can be introduced and illustrated in the context of simple ordinary differential equation (ODE) examples. This is what we do in the present document. By first working with ODEs, we keep the mathematical problems to be solved as simple as possible (but no simpler), thereby allowing full focus on understanding the key concepts and tools. The choice of topics in the forthcoming treatment of ODEs is therefore solely dominated by what carries over to numerical methods for PDEs.
Theory and practice are primarily illustrated by solving the very simple ODE \(u'=-au\), \(u(0)=I\), where \(a>0\) is a constant, but we also address the generalized problem \(u'=-a(t)u + b(t)\) and the nonlinear problem \(u'=f(u,t)\). The following topics are introduced:
- How to think when constructing finite difference methods, with special focus on the Forward Euler, Backward Euler, and Crank-Nicolson (midpoint) schemes
- How to formulate a computational algorithm and translate it into Python code
- How to make curve plots of the solutions
- How to compute numerical errors
- How to compute convergence rates
- How to verify an implementation and automate verification through nose tests in Python
- How to structure code in terms of functions, classes, and modules
- How to work with Python concepts such as arrays, lists, dictionaries, lambda functions, functions in functions (closures), doctests, unit tests, command-line interfaces, graphical user interfaces
- How to perform array computing and understand the difference from scalar computing
- How to conduct and automate large-scale numerical experiments
- How to generate scientific reports
- How to uncover numerical artifacts in the computed solution
- How to analyze the numerical schemes mathematically to understand why artifacts occur
- How to derive mathematical expressions for various measures of the error in numerical methods, frequently by using the sympy software for symbolic computation
- Introduce concepts such as finite difference operators, mesh (grid), mesh functions, stability, truncation error, consistency, and convergence
- Present additional methods for the general nonlinear ODE \(u'=f(u,t)\), which is either a scalar ODE or a system of ODEs
- How to access professional packages for solving ODEs
- How the model equation \(u'=-au\) arises in a wide range of phenomena in physics, biology, and finance
The exposition in a nutshell
Everything we cover is put into a practical, hands-on context. All mathematics is translated into working computing codes, and all the mathematical theory of finite difference methods presented here is motivated from a strong need to understand strange behavior of programs. Two fundamental questions saturate the text:
- How to we solve a differential equation problem and produce numbers?
- How to we trust the answer?