trajectory does indeed spiral outward, though to a less extreme degree than in the case of Euler’s method. Figure 5(e) depicts the particle’s trajectory for the case in which we solved Hamilton’s equations numerically using a symplectic method. In particular, one should note that there is no outward spiral, even as we zoom-in (Figure 5(f)).

Deriving a Simple Symplectic Integrator
---------------------------------------

Next, we sketch the derivation of a symplectic integrator. What follows is a paraphrasing of [@Liesite] and [@Liepaper]. For the sake of simplicity, we proceed in only one dimension. First, let $\mathcal{M}$ be the map corresponding to the solution of Hamilton’s equations for a Hamiltonian $H$. We may express our final variables, $x(\Delta s)$ and $p_x(\Delta s)$, in terms of our initial variables, $x(0)$ and $p_x(0)$, for some distance $\Delta s$ through a magnet component by

$\begin{bmatrix} x(\Delta s) \\ p_x(\Delta s) \end{bmatrix} = \mathcal{M} \begin{bmatrix} x(0) \\ p_x(0) \end{bmatrix}$.

Our goal is to derive a symplectic approximation to the map $\mathcal{M}$. To do this, we first expand our final variables using a Taylor series centered around $s = 0$. For simplicity, we do this only for $x$:

$$x(\Delta s) = \displaystyle\sum_{n=0}^{\infty} \frac{\Delta s^n}{n!} \frac{d^nx}{ds^n}\Bigr|_{\substack{s = 0}}.$$

To proceed, 