A rigorous derivation of the EOM for a charge in a dipolar field I've given the following question (and solution) to a class I am TAing for. The question is from Zangwill (Prob 4.5) and, for further reference, Zangwill cites R.S. Jones, American Journal of Physics 63, 1042 (1995).

Place a point electric dipole $\textbf{p} = p \hat{\textbf{z}}$ at the origin and release a point charge $q$ (initially at rest) from the point $(x_0,y_0,0)$ in the x-y plane away from the origin. Show that the particle moves periodically in a semi-circular arc.


Hint: Consider the requirement for zero radial acceleration for the point charge and show that it's equivalent to the expression you get when writing the conservation of energy for the system. You will also need the expression for Newton's Second Law in spherical coordinates. Don't worry if you can't do the calculation out fully, but your "argument" should be clear.


Answer: From Griffiths (3.103), we have that the field due to the dipole is
$$\textbf{E}(\textbf{r})= \frac{p}{4\pi \epsilon_0 r^3} \left(2 \cos \theta \ \hat{\textbf{r}}+\sin \theta \hat{\boldsymbol{\theta}} \right).$$
Now one can show (by differentiating the position vector $\textbf{r} = r\hat{\textbf{r}}$ in spherical coordinates after expanding the unit spherical vectors in the Cartesian unit vectors which are independent of time) that the acceleration of a particle written in spherical coordinates is given by
$$\textbf{a} = \ddot{\textbf{r}} = \hat{\textbf{r}}(\ddot{r} - r\dot{\theta}^2-r\dot{\phi}^2\sin^2\theta) +\hat{\boldsymbol{\theta}}(2\dot{r}\dot{\theta} +r\ddot{\theta} -r\dot{\phi}^2\sin\theta\cos\theta) + \hat{\boldsymbol{\phi}}(2\dot{r}\dot{\phi}\sin\theta + r\ddot{\phi}\sin\theta +2r\dot{\theta}\dot{\phi}cos\theta)$$
Then Newton's second law tells us for the particle with charge $q$ and mass $m$ that
\begin{align*}
    \textbf{F}= q\textbf{E}= \frac{pq}{4\pi \epsilon_0 r^3} \left(2 \cos \theta \hat{\textbf{r}}+\sin \theta \hat{\boldsymbol{\theta}} \right) 
    =m\textbf{a} = m\ddot{\textbf{r}} = m\left(\hat{\textbf{r}}(\ddot{r} - r\dot{\theta}^2-r\dot{\phi}^2\sin^2\theta) +\hat{\boldsymbol{\theta}}(2\dot{r}\dot{\theta} +r\ddot{\theta} -r\dot{\phi}^2\sin\theta\cos\theta) + \hat{\boldsymbol{\phi}}(2\dot{r}\dot{\phi}\sin\theta + r\ddot{\phi}\sin\theta +2r\dot{\theta}\dot{\phi}\cos\theta)\right)
\end{align*}
We could solve all this mess but it really is a mess. We'll argue on more physical grounds. We see in particular (from the $\hat{\boldsymbol{\phi}}$ component of the field) that the value of $\phi$ will not change throughout the problem (this is only valid because $\dot{\phi}(0) = 0$).
\
Now suppose the particle moves along a constant radius $r=R := \sqrt{x_0^2+y_0^2}$. Then we would have from the radial component that
$$ma_r = -\frac{mv^2}{R} = F_r = \frac{pq}{4\pi \epsilon_0 R^3} (2 \cos \theta). $$
But we can rearrange the above to see that this is precisely equivalent to
$$\frac{mv^2}{2} = - \frac{pq\cos \theta}{4\pi \epsilon_0 R^2} \iff \frac{mv^2}{2} + \frac{pq\cos \theta}{4\pi \epsilon_0 R^2} = 0.$$
We can identify this as the statement of conservation of energy in the system (note that the right-hand side is the potential energy of the charge in the dipolar field. Thus we see that conservation of energy holds if and only if the motion is along a constant $r=R$ path. We can now return to our original equation and select the $\hat{\boldsymbol{\theta}}$ component (after using that $\dot{\phi} = \dot{r} = 0$)  to see that we must have
$$mR\ddot{\theta} = \frac{pq\sin \theta}{4\pi \epsilon_0 R^3} \implies \ddot{\theta} = A \sin \theta$$
where we have defined the constant $A = pq/4m\pi \epsilon_0 R^2$.
This differential equation can be solved (numerically, as in the analogous case of a pendulum dropped from the horizontal) but it should be reasonable that given our initial $\dot{\theta} = 0$ condition we have periodic motion with only $\theta$ varying as shown below.


Now my question for Phys SE is how to make this more rigorous (if one wanted to). In particular, how could I precisely show (presumably using the $\phi$ component of Newton's second law) that $\phi$ does not change in this problem? I think from there I could make things precise, but I couldn't get that first step -- admittedly, it's a step which is obvious on physical grounds.
 A: This problem is most easily solved by using the Lagrangian formalism.
In spherical coordinates $(r, \theta, \varphi)$, the Lagrangian is given by $$ L= \frac{m}{2}\left( \dot{r}^2+r^2 \dot{\theta}^2+r^2\sin^2\! \theta \, \dot{\varphi}^2     \right) - \lambda \frac{\cos \theta}{r^2}, \quad \lambda=\frac{q \,p}{4 \pi \epsilon_0}.  $$ The coordinate $\varphi$ is cyclic (i.e. $\partial L / \partial \varphi =0$), which implies that $p_\varphi=\partial L / \partial \dot{\varphi}= mr^2 \sin^2 \! \theta \, \dot{\varphi}$ is a constant of motion. As $\partial L /\partial t=0$, the total energy $$ E = \frac{m}{2}\left(\dot{r}^2 +r^2 \dot{\theta}^2 + r^2 \sin^2 \! \theta \, \dot{\varphi}^2  \right) +\lambda\frac{\cos \theta}{r^2}=\frac{m}{2} \left(\dot{r}^2 +r^2 \dot{\theta}^2+\frac{p_\varphi^2}{m^2 r^2 \sin^2 \! \theta}\right)+\lambda \frac{\cos \theta}{r^2}$$ is conserved. The further steps are now straightforward.
Alternatively, one could also use cylindrical coordinates $(\rho, \varphi, z)$. In this case, $$ L= \frac{m}{2} \left(\dot{\rho}^2 +\rho^2 \dot{\varphi}^2+\dot{z}^2\right)-\lambda \frac{z}{(\rho^2 +z^2)^{3/2}}$$ with the constants of motion $p_\varphi = m \rho^2 \dot{\varphi} $  and  $$E= \frac{m}{2} \left( \dot{\rho}^2    \ +\frac{p_\varphi^2}{m^2 \rho^2}+\dot{z}^2\right) + \lambda \frac{z}{(\rho^2+z^2)^{3/2}}$$
