Programmierpraktikum




Claudius Gros, SS2012

Institut für theoretische Physik
Goethe-University Frankfurt a.M.

Numerical Integration of Differential Equations

first vs. second order differential equations

classical dynamics - second order

$$ \frac{d^2}{dt^2}\,\Big(\,m\,x(t)\,\Big) \ =\ F(t,x,\dot x), \qquad \ddot x(t) \ =\ f(t,x,\dot x) $$ $$ \begin{array}{rcl} \dot{x} & =& y \\ \dot{y} & = & f(t,x,y) \end{array} $$

first order differential equations

$$ \dot y \ =\ f(t,y) $$

Euler Integration

initial condition

$$ \dot y \ =\ f(t,y),\qquad y(t_0) \ =\ y_0, \qquad t_n \ =\ t_0\,+\,n\,h, \qquad n=0,\, 1,\,2,\, \dots $$

one step algorithm

$$ \frac{y(t+h)-y(t)}{h} \ \approx\ \dot y \ =\ f(t,y),\qquad y(t+h) \ \approx\ y(t) \,+\,h\,f(t,y) $$

$$ y(t_{n+1}) \ \approx\ y(t_n) \,+\,h\,f(t_n,y_n) $$

convergence considerations

Taylor expansion to second order

$$ y(t+h) \ \approx\ y(t)\,+\,h\,\dot y(t)\,+\,\frac{h^2}{2}\,\ddot y(t), \qquad\quad \dot y = f(t,y) $$

with

$$ \ddot y \ =\ {d\over dt} \dot y \ =\ {d\over dt} f(t,y) \ =\ f_t\,+\,f_y\,\dot y $$

and hence

$$ y(t+h)\,-\,y(t) \ =\ \Delta y\ \approx\ h\,\dot y\,+\,\frac{h^2}{2}\,\Big(\,f_t\,+\,f_y\,f\,\big) $$

accuracy to second order

$$ \Delta y\ =\ h\,f\,+\,\frac{h^2}{2}\,\Big(\,f_t\,+\,f_y\,f\,\big) $$

Runge-Kutta Ansatz

$$ \Delta y(t)\ =\ a\,f(t,y)\,+\,b\,f\Big(t+\alpha h,y+\beta h f\Big) $$

Runge-Kutta alogrithm - derivation

$$ \begin{array}{lcr} \Delta y(t)& =& a\,f(t,y)\,+\,b\,f\Big(t+\alpha h,y+\beta h f\Big) \\ & =& a\,f\,+\,b\,f\,+\,b\,\Big(f_t \alpha\,+\,f_y f\beta\Big)\,h \\ & :=& h\,f\,+\,\frac{h^2}{2}\,\Big(\,f_t\,+\,f_y\,f\,\big) \end{array} $$ $$ a+b\ =\ h,\qquad\quad \alpha\, b \ =\ \frac{h}{2} \qquad\quad \beta\, b \ =\ \frac{h}{2} $$

Runge-Kutta algorithm

simple Runge-Kutta

$$ y_{n+1}\ =\ y_n\,+\,\frac{h}{2}\ \Big[\, f(t_n,y_n)\,+\,f(t_n+h,y_n+hf(t_n,y_n)\, \Big] $$

classical Runge-Kutta algorithm

$$ \Delta y\ =\ \frac{h}{6}\ \Big[\, k_1\,+\,2k_2\,+\,2k_3\,+\,k_4\, \Big] $$

with

$$ k_1 = f(t,y)\,,\qquad k_2 = f\left(t+\frac{h}{2},y+\frac{hk_1}{2}\right) $$

and

$$ k_3 = f\left(t+\frac{h}{2},y+\frac{hk_2}{2}\right)\,,\qquad k_4 = f(t+h,y+hk_3) $$

example: Kepler problem

Newton's equation of motion

$$ m\dot{\vec v}\ =\ -\frac{GMm}{|\vec x|^3}\, \vec x , \qquad\quad \dot{\vec v}\ =\ -\frac{g}{|\vec x|^\alpha}\, \vec x , \qquad\quad \alpha = 3 $$

first order differentional equation

$$ \vec y \ =\ (\vec x, \vec v) \ =\ (x,y,\dot x,\dot y) , \qquad\quad \dot{\vec y} \ =\ \vec f(\vec y) $$ $$ \vec f(\vec y) \ =\ \big(\vec v, -g\vec x/|\vec x|^\alpha \big) , \qquad\quad |\vec x| = \sqrt{x^2+y^2} $$

integration of Kepler problem

Runge-Kutta for vector variables

$$ \dot{\vec y} \ =\ \vec f(t,\vec y) $$ $$ \Delta\vec y\ =\ \frac{h}{2}\ \Big(\, \vec f(t,\vec y)\,+\,\vec f(t+h,\vec y+h\vec f(t,\vec y)\, \Big) $$

exercise: integration