# Simple pendulum problem solver with error analysis

This webpage uses the Runge-Kutta-Fehlberg fourth-order method with fifth-order error checking (RKF45) to approximate the solution to the problem of the simple pendulum: $\dfrac{d^2 \theta}{dt^2} = -\dfrac{g}{l} \cos{\theta}$ where $$g$$ is the acceleration due to gravity in metres per second squared, $$l$$ is the length of the pendulum in metres, $$\theta$$ is the angle from the positive $$x$$ axis (in radians) and $$t$$ is the time in seconds. Below you can specify the various parameters for the problem we will solve. The error in $$\dot{\theta}$$ mentioned in the table below is approximated using this formula derived by integrating the above equation: $\dot{\theta} = \pm \sqrt{\dot{\theta}_0^2 + \dfrac{2g}{l}\left(\sin{\theta_0} - \sin{\theta}\right)}.$ Our $$\theta$$ approximations are substituted in, and our $$\dot{\theta}$$ RKF45 approximation is subtracted from this value. From this equation, the period $$T$$ of the problem is approximated when the conditions for periodicity are satisfied, namely using the equation: \begin{aligned} T &= 2 \left|\int_{\theta_\mathrm{min}}^{\theta_\mathrm{max}} \dfrac{d\theta}{\sqrt{\dot{\theta}_0^2 + \dfrac{2g}{l} (\sin{\theta_0} - \sin{\theta}})}\right| \end{aligned} where $$\theta_\mathrm{min}$$ and $$\theta_\mathrm{max}$$ are the two closest values for which $$\dot{\theta} = 0$$. $$T$$ is calculated using Chebyshev-Gauss quadrature (Simpson's rule could not be used as there are unremovable singularities at the endpoints which makes Simpson's rule markedly less accurate).
Parameter Value Explanation
Acceleration due to gravity in $$\mathrm{m} \cdot \mathrm{s}^{-2}$$.
Length of the pendulum rod in metres (m).
Starting time for the simulation in seconds (s).
End time for the simulation in seconds. The default $$t_f - t_0$$ value is equal to four times the period $$T$$ of the problem.
Angle from the positive $$x$$-axis in radians at time $$t_0$$.
First derivative of $$\theta$$ with respect to $$t$$ at $$t_0$$ (in $$\mathrm{radians}\cdot \mathrm{s}^{-1}$$).
Number of Chebyshev-Gauss quadrature nodes used to approximate the period of the problem. $$N \gt 1e7$$ usually freezes up the page.
Error tolerance in both $$\theta$$ and $$\dot{\theta}$$. $$\epsilon \lt$$2e-12 often freezes the webpage.
Initial guess for step size.

Information Data Notes
$$T$$: Period of the problem, auto-calculated.
$$\theta_\mathrm{min}$$ The value of $$\theta_\mathrm{min}$$ used in the above period equation.
$$\theta_\mathrm{max}$$ The value of $$\theta_\mathrm{max}$$ used in the above period equation.
RKF45 step number Number of steps used in our Runge-Kutta-Fehlberg approximation of the solution.