An ordinary differential equation is an equation of the form
$$G(t,x(t),x’(t),x’’(t),…)=0$$
$$ x’(t) = f(x(t),t)$$
Differential equations describe the dynamics of many systems:
In most cases the equations cannot be solved analytically: we need numerical methods.
Integration and ODEs are related.
Integration: $$ \frac{dx}{dt} = f(t)$$
Differential equation: $$ \frac{dx}{dt} = f(x(t),t)$$
An ODE where $f$ does not depend on $x(t)$ is an integration.
Consider explicit case where we can write
$$ \frac{dx}{dt}=f(x(t),t)$$
We start from the usual place: the definition of the derivative.
$$ \frac{dx}{dt} = \lim_{\Delta t\rightarrow 0} \frac{x(t+\Delta t)-x(t)}{\Delta t}$$
Solve for $x(t+\Delta t)$:
$$ x(t+\Delta t) \approx x(t) + \Delta t \frac{dx}{dt} = x(t) + \Delta t f(x(t),t) $$
Number of nuclei at time $t_0$: $N_0$
Mean lifetime of the decay process: $\tau$
Differential equation:
$$ \frac{dN}{dt} = - \frac{N(t)}{\tau}\equiv f(N,t)$$
Analytical solution:
$$ N(t)= N_0 e^{-t/\tau} $$
With the analytical solution we can relate the derivative and the number of nuclei:
The area under the curve is the change in the number of nuclei.
If we do not know the analytical solution things get more complicated, we need to:
So we get the algorithm
Different methods have different ways of estimating the area under the derivative curve. Euler’s method estimates the area under the derivative using the rectangle method
order | integration method | ODE method |
---|---|---|
0 | Rectangle | Euler |
1 | Trapezium rule | Heun |
2 | Simpson rule | Runge Kutta 4 |
You can now do the first part of assignment 3 which looks at radioactive decay using Euler’s method.
Heun’s method uses the same idea than the trapezium method to improve the estimate of the area under the derivative curve.
The algorithm is:
Heun’s method is one of the Runge Kutta family of methods that use multiple intermediate steps to determine the value of the function after a time step.
The most used is one involving four intermediate steps, it is called Runge-Kutta 4 but is it often simply named “Runge-Kutta”
The steps are :
$$ k = \frac{1}{6}\left(k_1+2k_2+2 k_3 + k_4\right)$$
ODE method | # function evaluations | error per step | total error |
---|---|---|---|
Euler | 1 | $\mathcal{O}(\Delta t)^2$ | $\mathcal{O}(\Delta t)^1$ |
Heun | 2 | $\mathcal{O}(\Delta t)^3$ | $\mathcal{O}(\Delta t)^2$ |
Runge Kutta 4 | 4 | $\mathcal{O}(\Delta t)^5$ | $\mathcal{O}(\Delta t)^4$ |
The error scaling is shown in this plot.
You can now finish assignment 3 looking at the radioactive decay using Runga-Kutta method.