Triple pendulum solver

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 triple pendulum. See this article for the derivation of the equations of motion.

Figure 1: Diagram of the triple pendulum.

The equations being solved in this simulation are

[M1l12μ2l1l2cosΔ21μ3l1l3cosΔ31μ2l1l2cosΔ21M2l22μ3l2l3cosΔ32μ3l1l3cosΔ31μ3l2l3cosΔ32M3l32][θ¨1θ¨2θ¨3]=[Qθ1μ1gl1cosθ1+μ2l1l2θ˙22sinΔ21+μ3l1l3θ˙32sinΔ31Qθ2μ2l2(l1θ˙12sinΔ21+gcosθ2)+μ3l2l3θ˙32sinΔ32Qθ3μ3l3(l1θ˙12sinΔ31+l2θ˙22sinΔ32+gcosθ3)]\begin{aligned} \begin{bmatrix} M_1 l_1^2 & \mu_2 l_1 l_2 \cos{\Delta_{21}} & \mu_3 l_1 l_3\cos{\Delta_{31}} \\ \mu_2 l_1 l_2 \cos{\Delta_{21}} &M_2 l_2^2 & \mu_3 l_2 l_3\cos{\Delta_{32}} \\ \mu_3 l_1 l_3 \cos{\Delta_{31}} & \mu_3 l_2 l_3 \cos{\Delta_{32}} & M_3 l_3^2 \end{bmatrix} \begin{bmatrix} \ddot{\theta}_1 \\ \ddot{\theta}_2 \\ \ddot{\theta}_3 \end{bmatrix} &= \begin{bmatrix} Q_{\theta_1} - \mu_1 g l_1 \cos{\theta_1} + \mu_2 l_1 l_2 \dot{\theta}_2^2 \sin{\Delta_{21}} + \mu_3 l_1 l_3 \dot{\theta}_3^2 \sin{\Delta_{31}} \\ Q_{\theta_2} - \mu_2 l_2(l_1\dot{\theta}_1^2\sin{\Delta_{21}}+g\cos{\theta_2}) + \mu_3 l_2 l_3 \dot{\theta}_3^2 \sin{\Delta_{32}}\\ Q_{\theta_3} - \mu_3 l_3 (l_1\dot{\theta}_1^2 \sin{\Delta_{31}} + l_2\dot{\theta}_2^2 \sin{\Delta_{32}} + g\cos{\theta_3}) \end{bmatrix} \end{aligned}

Where M1=m1b+m1r3+m2b+m2r+m3b+m3rM_1 = m_{1b} + \dfrac{m_{1r}}{3} + m_{2b} + m_{2r} + m_{3b} + m_{3r}, M2=m2b+m2r3+m3b+m3rM_2 = m_{2b} + \dfrac{m_{2r}}{3} + m_{3b} + m_{3r}, M3=m3b+m3r3M_3 = m_{3b} + \dfrac{m_{3r}}{3}, μ1=m1b+m1r2+m2b+m2r+m3b+m3r\mu_1 = m_{1b} + \dfrac{m_{1r}}{2} + m_{2b} + m_{2r} + m_{3b} + m_{3r}, μ2=m2b+m2r2+m3b+m3r\mu_2 = m_{2b} + \dfrac{m_{2r}}{2} + m_{3b} + m_{3r}, μ3=m3b+m3r2\mu_3 = m_{3b} + \dfrac{m_{3r}}{2} and Δij=θiθj\Delta_{ij} = \theta_i - \theta_j.

Simulation parameter form.
Parameter Value Explanation
Gravitational acceleration (in ms2\mathrm{m}\cdot \mathrm{s}^{-2}).
Length of pendulum 1 in metres.
Length of pendulum 2 in metres.
Length of pendulum 3 in metres.
Mass of pendulum bob 1 in kilograms.
Mass of pendulum rod 1 in kilograms.
Mass of pendulum bob 2 in kilograms.
Mass of pendulum rod 2 in kilograms.
Mass of pendulum bob 3 in kilograms.
Mass of pendulum rod 3 in kilograms.
Linear dissipation coefficient of pendulum bob 1.
Linear dissipation coefficient of pendulum rod 1.
Quadratic dissipation coefficient of pendulum bob 1.
Quadratic dissipation coefficient of pendulum rod 1.
Linear dissipation coefficient for pendulum bob 2.
Linear dissipation coefficient for pendulum rod 2.
Quadratic dissipation coefficient for pendulum bob 2.
Quadratic dissipation coefficient for pendulum rod 2.
Linear dissipation coefficient for pendulum bob 3.
Linear dissipation coefficient for pendulum rod 3.
Quadratic dissipation coefficient for pendulum bob 3.
Quadratic dissipation coefficient for pendulum rod 3.
End time for the simulation in seconds.
Initial value of θ1\theta_1 in radians.
Initial value of θ˙1\dot{\theta}_1 in radians per second.
Initial value of θ2\theta_2 in radians.
Initial value of θ˙2\dot{\theta}_2 in radians per second.
Initial value of θ3\theta_3 in radians.
Initial value of θ˙3\dot{\theta}_3 in radians per second.
Error tolerance.
Tolerance type, can be either absolute (0) or relative (1).
Initial step size.
Minimum allowed step size.
Time increment for skipping ahead in animation.
Time you want to skip ahead to in animation when you press the skip button.
Width (in px) of Plotly windows used for plotting and animation below.
Height (in px) of Plotly windows used for plotting and animation below.
Proportion of animation time passed per real time. tScale=1.0t_{\mathrm{Scale}}=1.0 means animation and real time match. tScale<1.0t_{\mathrm{Scale}}<1.0 means the animation is going more slowly than real time. tScale>1.0t_{\mathrm{Scale}}>1.0 means it is going more rapidly.
Opacity of the lines in the 3D phase space animation. Customizable in case you need to tweak it in order to see the red dot marker.