I am trying to implement a spherical pendulum. The Lagrangian (which I haven't fully understood so yet) based on $l$, θ and φ taken from this page result in the equations:
\begin{align} \ddot{\theta}&=\dot{\varphi}^2\sin\theta\cos\theta-\frac{g}{l}\sin\theta\\ \ddot{\varphi}&=-2\dot{\theta}\dot{\varphi}\cot\theta \end{align}
I am treating $\ddot{\theta}$ as the acceleration and of $\dot{\theta}$ as the velocity of $\theta$. Is this correct? Now, each step of the motion is implemented as follows (Python):
theta_f = pow(phi_v, 2) * sin(theta) * cos(theta) - G / L * sin(theta)
phi_f = - 2 * theta_v * phi_v / tan(theta)
theta_v += theta_f / timesteps
phi_v += phi_f / timesteps
theta += theta_v
phi += phi_v
This works as long as phi_v ($\dot{\phi}$) is 0 or close to 0.
If $\dot{\phi}_\text{initial} > 0$, the movement is erroneous.
My initial values are
theta = 0.8
phi = 0.5
timesteps = 60
L ~ 2
G = 2.0
theta_v = 0.0
phi_v = 0.1
After a few iterations, the code produces a math range error as phi_v gets too large. I have found this question which could explain the math rounding error.
I am using using 60 samples per second, because there will be real-time interaction. Approximated values will be totally fine, but I can't believe that the current state is simply and approximation error.
How can I correct my code to simulate the spherical pendulum?

