{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial 10 - Initial value problems" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "nitial value problems of ordinary differential equations, explicit and implicit Euler method, Runge-Kutta methods, Leap-frog, Adams-Bashford, Adams-Moulton, predictor-corrector, Bulirsch-Stoer algorithm, stiff equations." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from scipy import integrate, optimize" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Runge-Kutta methods" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The [Runge–Kutta methods](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods) are a family of [explicit and implicit](https://en.wikipedia.org/wiki/Explicit_and_implicit_methods) [iterative](https://en.wikipedia.org/wiki/Iterative_method) methods for the numerical solution of the [initial value problem](https://en.wikipedia.org/wiki/Initial_value_problem)\n", "\n", "$$\n", "\\frac{dy}{dx} = f(x, y), \\quad y(x_0) = y_0.\n", "$$\n", "\n", "Here $ y $ is an unknown function (scalar or vector) of $ x $. The function $ f $ and the [initial conditions](https://en.wikipedia.org/wiki/Initial_condition) $ x_0 $, $ y_0 $ are given. The Runge–Kutta methods take the form\n", "\n", "$$\n", "y_{i + 1} = y_{i} + h \\sum_{j = 1}^{r} b_{j} k_{j}(h), \\quad i = 0, \\dots, n - 1.\n", "$$\n", "\n", "where\n", "\n", "$$\n", "k_j = f(x_i + c_j h, y_i + h \\sum_{l = 1}^{j - 1} a_{jl} k_l)\n", "$$\n", "\n", "in the case of explicit methods and\n", "\n", "$$\n", "k_j = f(x_i + c_j h, y_i + h \\sum_{l = 1}^{r} a_{jl} k_l)\n", "$$\n", "\n", "in the case of implicit methods. Here, $ y_i $ and $ y_{i + 1} $ are the approximations of $ y(x_i)$ and $ y(x_{i + 1}) $, respectively, and $ h > 0 $ is a step size. To specify a particular method, one needs to provide the integer $ r $ (the number of stages), and the coefficients $ a_{ij} $, $ b_i $, and $ c_i $ (see the [list of Runge-Kutta methods](https://en.wikipedia.org/wiki/List_of_Runge%E2%80%93Kutta_methods)). The matrix $ (a_{ij}) $ is called the Runge–Kutta matrix, while the $ b_i $ and $ c_i $ are known as the weights and the nodes. These data can be arranged in a Butcher tableau:\n", "\n", "$$\n", "\\begin{array}\n", "{c|cccc}\n", "c_1 & a_{11} & a_{12} & \\cdots & a_{1r} \\\\\n", "c_2 & a_{21} & a_{22} & \\cdots & a_{2r} \\\\\n", "\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n", "c_r & a_{r1} & a_{r2} & \\cdots & a_{rr}\\\\\n", "\\hline\n", "& b_1 & b_2 & \\cdots & b_{r}\n", "\\end{array}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "