Re:Double Pendulum in fewer than 100 lines of JavaScript
by simias on Wednesday July 09, 2014 @05:19AM
(#8008741)
I agree with the parent, I think you must have a bug somewhere. For many positions of the sliders the movement seems very erratic, the pendulums suddenly bounce back or accelerate without any apparent reason. Especially when you start moving the top slider to the right (though not necessarily all the way to the right).
Or maybe I just don't understand how double pendulums work...
In any case, when you max out the first scrollbar, then m_1/M_1 approaches zero. Then the denominators of the Lagrange equation will be close to zero when \theta_1 is close to \theta_2. Thus things become unstable.
Anyway, a symplectic integrator [1] would be more suitable for this problem, since it has the beautiful property of conserving energy.
[0] https://en.wikipedia.org/wiki/RK4#The_Runge.E2.80.93Kutta_me... [1] https://en.wikipedia.org/wiki/Symplectic_integrator