08 Ordinary Differential Equations (ODEs)
16 Feb 2016Most physical phenomena are ultimately described by a relationship between changing quantities, resulting in differential equations. If such an equation only contains one independent variable (such as time) and hence only total derivatives (and no partial derivatives) we classify it as an ordinary differential equation (ODE). An ODE of order contains no derivatives higher than the -th derivative:
The dependent variable is a function of the independent variable and is the -th derivative with respect to . A linear ODE only contains first powers of or its derivatives. A non-linear ODE may contain higher powers. There often exist methods to solve linear ODEs analytically but this is impossible for most non-linear ODEs. Solutions of an ODE are fixed by the initial conditions1, e.g., and similar for all higher derivatives. For an ODE of order , exactly initial conditions are needed.
Using ODE integration algorithms (integrators) we can solve linear and non-linear ODEs of any order numerically. The basic idea is to start with the initial conditions and then propagate for a small step to numerically compute and all its derivatives. By repeating the process, one extrapolates from the initial condition to any "later" value of .
We will first study the simplest integrator, the Euler algorithm, and then look at a more robust class of integrators, the Runge-Kutta schemes.
ODEs, standard form, and principles of integrators
The first part of this lesson introduces the formalism and the basic ideas behind integration algorithms.
The Jupyter notebook 08_ODEs.ipynb contains the lecture notes. Skeleton code for in-class problem exercises is in 08_ODEs-students-1.ipynb.2
Accuracy and performance of Euler and Runge-Kutta integrators
The second part shows how to assess the accuracy of integration
algorithms and analyzes in more depth the simple
Euler integrator and the
Runge-Kutta methods,
namely rk2
and rk4
. As examples we use the simple 1D
harmonic oscillator with potential energy function , an anharmonic oscillator (), and a 6-th power oscillator ().
The Jupyter notebook 08_ODE_integrators.ipynb contains the lecture notes. Skeleton code for in-class problem exercises can be found in the notebook 08_ODE_integrators-students-1.ipynb.2
Verlet integrators
The third part introduces a different class of integrators: time reversible (and symplectic) integrators such as the velocity Verlet algorithm, which have worse accuracy than e.g. RK4 but long term stability.
Class material
The Jupyter notebook 08_ODE-integrators-verlet.ipynb contains the lecture notes (which were
life-coded); the make use of the module integrators2.py
. Skeleton
code for in-class problem exercises can be found in the notebook
08_ODE_integrators-students-1.ipynb.2
Additional resources:
- Computational Physics: Chapter 9
- scipy.integrate for high performance integration algorithms for Python, in particular see scipy.integrate.odeint() and scipy.integrate.ode().
- Weisstein, Eric W. "Ordinary Differential Equation." From MathWorld — A Wolfram Web Resource.
- Numerical Recipes in C, WH Press, SA Teukolsky, WT Vetterling, BP Flannery. 2nd ed, 2002. Cambridge University Press. Chapter 16.
Footnotes
-
Solutions to ODEs can also be restricted by boundary conditions (values of the solution on the domain boundary) but this leads to difficult Eigenvalue problems and will not be considered in this lesson. ↩
-
As usual,
git pull
the resources repository to get a local copy of the notebook. Then copy the notebook into your work directory in order to complete the exercises. ↩ ↩2 ↩3