|

Derivation of the equations (by AI)

Here is the full, unabbreviated derivation of the equations of motion for a double pendulum using Lagrangian mechanics, written by AI (Gemini).

In physics and mathematics, the dot above a variable is Newton’s notation for the time derivative. It is a shorthand way of saying how much this value is changing with respect to time.

  • θ\theta (Theta): The Angle (Position).

  • θ˙\dot{\theta} (Theta-dot): The Angular Velocity (How fast the angle is changing).1 This is the a1_v and a2_v in your JavaScript code.2

  • θ¨\ddot{\theta} (Theta-double-dot): The Angular Acceleration (How fast the velocity is changing). This is the a1_a and a2_a that your getAccelerations function calculates.

1. Coordinate Transformation

We define the positions (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) of the two masses in terms of the angles θ1\theta_1 and θ2\theta_2. We assume the yy-axis points downwards.

x1=l1sinθ1x_1 = l_1 \sin \theta_1

y1=l1cosθ1y_1 = l_1 \cos \theta_1

x2=l1sinθ1+l2sinθ2x_2 = l_1 \sin \theta_1 + l_2 \sin \theta_2

y2=l1cosθ1+l2cosθ2y_2 = l_1 \cos \theta_1 + l_2 \cos \theta_2

2. The Lagrangian (LL)

The Lagrangian is the difference between the Kinetic Energy (TT) and the Potential Energy (VV).

Kinetic Energy (TT):

Summing T=12mv2{\displaystyle T = \frac{1}{2}mv^2} for both masses (where v2=x˙2+y˙2v^2 = \dot{x}^2 + \dot{y}^2):

T=12m1l12θ˙12+12m2[l12θ˙12+l22θ˙22+2l1l2θ˙1θ˙2cos(θ1θ2)]{\displaystyle T = \frac{1}{2} m_1 l_1^2 \dot{\theta}_1^2 + \frac{1}{2} m_2 \left[ l_1^2 \dot{\theta}_1^2 + l_2^2 \dot{\theta}_2^2 + 2 l_1 l_2 \dot{\theta}_1 \dot{\theta}_2 \cos(\theta_1 - \theta_2) \right] }

Potential Energy (VV):

Taking the pivot as the zero-energy reference:

V=(m1+m2)gl1cosθ1m2gl2cosθ2V = -(m_1 + m_2) g l_1 \cos \theta_1 - m_2 g l_2 \cos \theta_2

Lagrangian (L=TVL = T - V):

L=12(m1+m2)l12θ˙12+12m2l22θ˙22+m2l1l2θ˙1θ˙2cos(θ1θ2)+(m1+m2)gl1cosθ1+m2gl2cosθ2{\displaystyle L = \frac{1}{2}(m_1 + m_2)l_1^2\dot{\theta}_1^2 + \frac{1}{2}m_2l_2^2\dot{\theta}_2^2 + m_2l_1l_2\dot{\theta}_1\dot{\theta}_2\cos(\theta_1-\theta_2) + (m_1+m_2)gl_1\cos\theta_1 + m_2gl_2\cos\theta_2}

3. Euler-Lagrange Equations

To find the equations of motion, we solve the following for each angle θi\theta_i:

ddt(Lθ˙i)Lθi=0{\displaystyle \frac{d}{dt} \left( \frac{\partial L}{\partial \dot{\theta}_i} \right) - \frac{\partial L}{\partial \theta_i} = 0}

Performing the partial derivatives and time derivatives leads to two coupled second-order differential equations:

  1. (m1+m2)l1θ¨1+m2l2θ¨2cos(θ1θ2)+m2l2θ˙22sin(θ1θ2)+(m1+m2)gsinθ1=0(m_1+m_2)l_1\ddot{\theta}_1 + m_2l_2\ddot{\theta}_2\cos(\theta_1-\theta_2) + m_2l_2\dot{\theta}_2^2\sin(\theta_1-\theta_2) + (m_1+m_2)g\sin\theta_1 = 0

  2. l2θ¨2+l1θ¨1cos(θ1θ2)l1θ˙12sin(θ1θ2)+gsinθ2=0l_2\ddot{\theta}_2 + l_1\ddot{\theta}_1\cos(\theta_1-\theta_2) - l_1\dot{\theta}_1^2\sin(\theta_1-\theta_2) + g\sin\theta_2 = 0

4. Final Accelerations (Implementation Form)

By solving the above linear system for θ¨1\ddot{\theta}_1 and θ¨2\ddot{\theta}_2, we obtain the formulas used in the getAccelerations function:

Acceleration of the first arm (θ¨1\ddot{\theta}_1):

θ¨1=g(2m1+m2)sinθ1m2gsin(θ12θ2)2sin(θ1θ2)m2(θ˙22l2+θ˙12l1cos(θ1θ2))l1(2m1+m2m2cos(2θ12θ2)){\displaystyle \ddot{\theta}_1 = \frac{-g(2m_1+m_2)\sin\theta_1 - m_2g\sin(\theta_1-2\theta_2) - 2\sin(\theta_1-\theta_2)m_2( \dot{\theta}_2^2l_2 + \dot{\theta}_1^2l_1\cos(\theta_1-\theta_2) )}{l_1(2m_1+m_2-m_2\cos(2\theta_1-2\theta_2))}}
Acceleration of the second arm (θ¨2\ddot{\theta}_2):

θ¨2=2sin(θ1θ2)(θ˙12l1(m1+m2)+g(m1+m2)cosθ1+θ˙22l2m2cos(θ1θ2))l2(2m1+m2m2cos(2θ12θ2)){\displaystyle \ddot{\theta}_2 = \frac{2\sin(\theta_1-\theta_2) \left( \dot{\theta}_1^2l_1(m_1+m_2) + g(m_1+m_2)\cos\theta_1 + \dot{\theta}_2^2l_2m_2\cos(\theta_1-\theta_2) \right)}{l_2(2m_1+m_2-m_2\cos(2\theta_1-2\theta_2))} }