Authors: | Hans Petter Langtangen |
---|---|
Date: | Jul 24, 2015 |
Finite difference methods for partial differential equations (PDEs) employ a range of concepts and tools that can be introduced and illustrated by way simple ordinary differential equation (ODE) examples. The aim of the present document is to lay a foundation for understanding numerical methods for PDEs by first meeting the fundamental ideas in a simpler ODE setting. With the ODEs, the mathematical problems are kept as simple as possible (but no simpler!), allowing full focus on the understanding of key concepts and tools. The choice of ODE topics to be covered here is thus solely determined by what carries over to the world of numerical solution 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 more general model problem \(u'=-a(t)u + b(t)\) and the completely general, nonlinear problem \(u'=f(u,t)\). The following list of topics will be elaborated on.
- 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 test that an implementation is correct (verification) and how to automate tests through test functions and unit testing
- How to work with Python concepts such as arrays, lists, dictionaries, lambda functions, functions in functions (closures)
- How to perform array computing and understand the difference from scalar computing
- 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 computations- How to understand concepts such as finite difference operators, mesh (grid), mesh functions, stability, truncation error, consistency, and convergence
- How to solve the general nonlinear ODE \(u'=f(u,t)\), which is either a scalar ODE or a system of ODEs (i.e., \(u\) and \(f\) can either be a function or a vector of functions)
- 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 why we occasionally obtain strange results from the programs. Two fundamental questions saturate the text:
- How do we solve a differential equation problem and produce numbers?
- How do we know that the answer is correct?
Besides answering these two questions, you will learn a lot about mathematical modeling in general and the interplay between physics, mathematics, numerical methods, and computer science.