HEAD | PREVIOUS |

Ordinary Differential Equations

$\frac{{d}^{N}y}{{\mathit{dx}}^{N}}=f(\frac{{d}^{N-1}y}{{\mathit{dx}}^{N-1}},\frac{{d}^{N-2}y}{{\mathit{dx}}^{N-2}},\dots ,\frac{\mathit{dy}}{\mathit{dx}},y,x)$ | $(2.1)$ |

$\frac{{d}^{i}y}{{\mathit{dx}}^{i}}={y}^{(i)}\mathrm{\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}}i=1,2,\dots ,N-1.$ | $(2.2)$ |

$\frac{d}{\mathit{dx}}{y}^{(i)}={f}_{i}({y}^{(N-1)},{y}^{(N-2)},\dots ,{y}^{(1)},{y}^{(0)},x),\mathrm{\hspace{1em}\hspace{1em}\hspace{1em}}i=0,1,\dots ,N-1$ | $(2.3)$ |

$\frac{d}{\mathit{dx}}\left(\begin{array}{c}\hfill {y}^{(0)}\hfill \\ \hfill {y}^{(1)}\hfill \\ \hfill :\hfill \\ \hfill {y}^{(N-1)}\hfill \end{array}\right)=\left(\begin{array}{c}\hfill {f}_{0}\hfill \\ \hfill {f}_{1}\hfill \\ \hfill :\hfill \\ \hfill {f}_{N-1}\hfill \end{array}\right)=\left(\begin{array}{c}\hfill {y}^{(1)}\hfill \\ \hfill {y}^{(2)}\hfill \\ \hfill :\hfill \\ \hfill f({y}^{(N-1)},{y}^{(N-2)},\dots ,{y}^{(1)},{y}^{(0)},x)\hfill \end{array}\right).$ | $(2.4)$ |

$\frac{d}{\mathit{dt}}\mathit{x}=\mathit{v}.$ | $(2.5)$ |

$\frac{d}{\mathit{dt}}\mathit{v}=\frac{e}{{m}_{p}}\mathit{v}\times \mathit{B}=\mathit{f}(\mathit{v}),$ | $(2.6)$ |

Figure 2.1: Orbit of the velocity of a particle moving in a uniform
magnetic field is a circle in *velocity-space* perpendicular
to the field ($B=B\hat{\mathit{z}}$ here).

If, for our proton orbit, $\mathit{B}$ is not uniform, but varies with
position, then we need to know both position $\mathit{x}$, and velocity
$\mathit{v}$ at all times along the orbit to solve it. The system then
involves six-dimensional vectors consisting of the components of
$\mathit{x}$ and $\mathit{v}$:
$\frac{d}{\mathit{dt}}\left(\begin{array}{c}\hfill {x}_{1}\hfill \\ \hfill {x}_{2}\hfill \\ \hfill {x}_{3}\hfill \\ \hfill {v}_{1}\hfill \\ \hfill {v}_{2}\hfill \\ \hfill {v}_{3}\hfill \end{array}\right)=\left(\begin{array}{c}\hfill {v}_{1}\hfill \\ \hfill {v}_{2}\hfill \\ \hfill {v}_{3}\hfill \\ \hfill ({v}_{2}{B}_{3}-{v}_{3}{B}_{2})e/{m}_{p}\hfill \\ \hfill ({v}_{3}{B}_{1}-{v}_{1}{B}_{3})e/{m}_{p}\hfill \\ \hfill ({v}_{1}{B}_{2}-{v}_{2}{B}_{1})e/{m}_{p}\hfill \end{array}\right).$ | $(2.7)$ |

$\frac{d}{\mathit{dt}}{v}_{1}=\mathit{\Omega}{v}_{2},\hspace{0.5em}\frac{d}{\mathit{dt}}{v}_{2}=-\mathit{\Omega}{v}_{1}\mathrm{\hspace{1em}\hspace{1em}\hspace{1em}}\Rightarrow \mathrm{\hspace{1em}\hspace{1em}\hspace{1em}}\frac{{d}^{2}{v}_{1}}{{\mathit{dt}}^{2}}=-{\mathit{\Omega}}^{2}{v}_{1},\hspace{0.5em}\frac{{d}^{2}{v}_{2}}{{\mathit{dt}}^{2}}=-{\mathit{\Omega}}^{2}{v}_{2}.$ | $(2.8)$ |

Figure 2.2: Illustrating finite difference representation of a
continuous function.

The natural way to discretize the
derivative is to write
$\frac{\mathit{dy}}{\mathit{dx}}\approx \frac{{y}_{n+1}-{y}_{n}}{{x}_{n+1}-{x}_{n}}=f(y,x),$ | $(2.9)$ |

${y}_{n+1}={y}_{n}+f(y,x)({x}_{n+1}-{x}_{n}).$ | $(2.10)$ |

$f(y(x),x)=f({y}_{n},{x}_{n})+\frac{{\mathit{df}}_{n}}{\mathit{dx}}\mathit{\delta}x+\frac{{d}^{2}{f}_{n}}{{\mathit{dx}}^{2}}\frac{\mathit{\delta}{x}^{2}}{2!}+O(\mathit{\delta}{x}^{3})$ | $(2.11)$ |

$\mathit{\delta}y={f}_{n}\mathit{\delta}x+\frac{{\mathit{df}}_{n}}{\mathit{dx}}\frac{\mathit{\delta}{x}^{2}}{2!}+\frac{{d}^{2}{f}_{n}}{{\mathit{dx}}^{2}}\frac{\mathit{\delta}{x}^{3}}{3!}+O(\mathit{\delta}{x}^{4})$ | $(2.12)$ |

$\mathit{\delta}y-\mathit{\delta}{y}^{(1)}=\mathit{\epsilon}=\frac{{\mathit{df}}_{n}}{\mathit{dx}}\frac{\mathit{\delta}{x}^{2}}{2!}+\frac{{d}^{2}{f}_{n}}{{\mathit{dx}}^{2}}\frac{\mathit{\delta}{x}^{3}}{3!}+O(\mathit{\delta}{x}^{4}).$ | $(2.13)$ |

Figure 2.3: Optional steps using derivative function evaluated at $n$
or $n+1$.

We can do better. Our error arose because we approximated the
derivative function by using its value only at ${x}_{n}$. But once we've
moved to the next position, and know (with some inaccuracy) the value
${y}_{n+1}$ and hence ${f}_{n+1}$ there, we can evaluate $\mathit{\delta}y=\frac{1}{2}({f}_{n}+{f}_{n+1}^{(1)})\mathit{\delta}x,$ | $(2.14)$ |

$\mathit{\delta}y={f}_{n}\mathit{\delta}x+\frac{{\mathit{df}}_{n}}{\mathit{dx}}\frac{\mathit{\delta}{x}^{2}}{2!}+O(\mathit{\delta}{x}^{3}),$ | $(2.15)$ |

$\begin{array}{ccc}\multicolumn{1}{c}{{f}^{(0)}}& =\hfill & f({y}_{n},{x}_{n})\hfill \\ \multicolumn{1}{c}{{f}^{(1)}}& =\hfill & f({y}_{n}+{f}^{(0)}\frac{\mathit{\Delta}}{2},{x}_{n}+\frac{\mathit{\Delta}}{2})\hfill \\ \multicolumn{1}{c}{{f}^{(2)}}& =\hfill & f({y}_{n}+{f}^{(1)}\frac{\mathit{\Delta}}{2},{x}_{n}+\frac{\mathit{\Delta}}{2})\hfill & \hfill \hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}\hspace{1em}(2.16)\\ \multicolumn{1}{c}{{f}^{(3)}}& =\hfill & f({y}_{n}+{f}^{(2)}\mathit{\Delta},{x}_{n}+\mathit{\Delta}),\hfill \end{array}$ |

in which two steps are to the half-way point $\frac{\mathit{\Delta}}{2}$. Then the following combination

${y}_{n+1}={y}_{n}+(\frac{{f}^{(0)}}{6}+\frac{{f}^{(1)}}{3}+\frac{{f}^{(2)}}{3}+\frac{{f}^{(3)}}{6})\mathit{\Delta}+O({\mathit{\Delta}}^{5}),$ | $(2.17)$ |

$\frac{\mathit{dy}}{\mathit{dx}}=-ky,$ | $(2.18)$ |

${y}_{n+1}={y}_{n}+f({y}_{n},{x}_{n})({x}_{n+1}-{x}_{n})={y}_{n}(1-k\mathit{\Delta}).$ | $(2.19)$ |

${y}_{n}={y}_{0}(1-k\mathit{\Delta}{)}^{n},$ | $(2.20)$ |

Figure 2.5: Explicit numerical integration of eq. (2.18), using eq. (2.19) leads to an oscillatory instability if the step
length is too long. Four step lengths are shown $k\mathit{\Delta}=0.5,0.9,1.5,2.1$.

In general, an explicit discrete advancing scheme requires the step in
the independent variable to be less than some value (in this case
$2/k$) in order to achieve stability.
An ${y}_{n+1}={y}_{n}+f({y}_{n+1},{x}_{n+1})({x}_{n+1}-{x}_{n})={y}_{n}-k{y}_{n+1}\mathit{\Delta}.$ | $(2.21)$ |

${y}_{n+1}(1+k\mathit{\Delta})={y}_{n}.$ | $(2.22)$ |

${y}_{n}={y}_{0}(1+k\mathit{\Delta}{)}^{-n}.$ | $(2.23)$ |

$\frac{d}{\mathit{dx}}\mathbf{y}=\mathbf{A}\mathbf{y},\mathrm{\hspace{1em}\hspace{1em}\hspace{1em}}\text{where for example}\mathrm{\hspace{1em}\hspace{1em}\hspace{1em}}\mathbf{A}=\left(\begin{array}{cc}\hfill 0\hfill & \hfill -1\hfill \\ \hfill 100\hfill & \hfill -101\hfill \end{array}\right).$ | $(2.24)$ |

${\mathbf{y}}_{n+1}=(\mathbf{I}-\mathit{\Delta}.\mathbf{A}{)}^{-1}{\mathbf{y}}_{n}.$ | $(2.25)$ |

Each of the drift and kick steps can be simple explicit advances. But because the velocities are suitably time-shifted relative to the positions and accelerations, the result is

$\frac{{d}^{2}y}{{\mathit{dx}}^{2}}+2\mathit{\alpha}\frac{\mathit{dy}}{\mathit{dx}}+{k}^{2}y=g(x),$ | $(2.26)$ |

First, reduce the equation to standard first-order form by writing

$\frac{d}{\mathit{dx}}\left(\begin{array}{c}\hfill {y}^{(0)}\hfill \\ \hfill {y}^{(1)}\hfill \end{array}\right)=\left(\begin{array}{c}\hfill {y}^{(1)}\hfill \\ \hfill g(x)-2\mathit{\alpha}{y}^{(1)}-{k}^{2}{y}^{(0)}\hfill \end{array}\right)=\left(\begin{array}{cc}\hfill 0\hfill & \hfill 1\hfill \\ \hfill -{k}^{2}\hfill & \hfill -2\mathit{\alpha}\hfill \end{array}\right)\left(\begin{array}{c}\hfill {y}^{(0)}\hfill \\ \hfill {y}^{(1)}\hfill \end{array}\right)+\left(\begin{array}{c}\hfill 0\hfill \\ \hfill g(x)\hfill \end{array}\right).$ | $(2.27)$ |

$0=\left|\begin{array}{cc}\hfill -\mathit{\lambda}\hfill & \hfill 1\hfill \\ \hfill -{k}^{2}\hfill & \hfill -\mathit{\lambda}-2\mathit{\alpha}\hfill \end{array}\right|={\mathit{\lambda}}^{2}+2\mathit{\alpha}\mathit{\lambda}+{k}^{2},$ | $(2.28)$ |

$\mathit{\lambda}=-\mathit{\alpha}\pm \sqrt{{\mathit{\alpha}}^{2}-{k}^{2}}.$ | $(2.29)$ |

$|F{|}^{2}=(1-\mathit{\alpha}\mathit{\Delta}{)}^{2}+({k}^{2}-{\mathit{\alpha}}^{2}){\mathit{\Delta}}^{2}=1-2\mathit{\alpha}\mathit{\Delta}+{k}^{2}{\mathit{\Delta}}^{2}.$ | $(2.30)$ |

2. Accuracy order of ODE schemes. For notational convenience, we start at $x=y=0$ and consider a small step in $x$ and $y$ of the ODE $\mathit{dy}/\mathit{dx}=f(y,x)$. The Taylor expansion of the derivative function along the orbit is

$f(y(x),x)={f}_{0}+\frac{{\mathit{df}}_{0}}{\mathit{dx}}x+\frac{{d}^{2}{f}_{0}}{{\mathit{dx}}^{2}}\frac{{x}^{2}}{2!}+\dots$ | $(2.31)$ |

(a) | Integrate $\frac{\mathit{dy}}{\mathit{dx}}=f(y(x),x)$ term by term to find the solution for $y$ to third-order in $x$. |

(b) | Suppose ${y}_{1}={f}_{0}x$. Find ${y}_{1}-y(x)$ to second-order in $x$. |

(c) | Now consider ${y}_{2}=f({y}_{1},x)x,$ show that it is equal to $f(y,x)x$ plus a term that is third-order in $x$. |

(d) | Hence find ${y}_{2}-y$ to second-order in $x$. |

(e) | Finally show that ${y}_{3}=\frac{1}{2}({y}_{1}+{y}_{2})$ is equal to $y$
accurate to second-order in $x$. |

$\frac{\mathit{dy}}{\mathit{dt}}=-\mathit{\omega}y$ |

with $\mathit{\omega}$ a positive constant, starting from $y(0)=1$, proceeding as follows. (a) Use the explicit Euler scheme

${y}_{n+1}={y}_{n}-\mathit{\Delta}t\mathit{\omega}{y}_{n}.$ |

(b) Use the implicit scheme

${y}_{n+1}={y}_{n}-\mathit{\Delta}t\mathit{\omega}{y}_{n+1}.$ |

In each case, find numerically the

(c) Find experimentally the timestep value at which the explicit scheme becomes unstable. Verify that the implicit scheme never becomes unstable.

HEAD | NEXT |