Logo Xingxin on Bug

Deriving Euler-Lagrange Equation of a Simple Double Pendulum

April 8, 2026
9 min read

Recently, I have been expanding my knowledge in control theory by following Russ Tedrake’s MIT 6.8210: Underactuated Robotics. This blog post is an “expansion” on the Simple Double Pendulum found in the Appendix B Multi-Body Dynamics.

Returning from the industry after working as a software engineer at Autodesk, I realized I had forgotten a lot of the math I learned in school. Therefore, I saw this as a perfect opportunity to take the given equations and derive them step by step. It serves as a great, hands-on refresher for calculus, partial derivatives, and applying the chain rule.

Problem

The example in Russ’s notes is stated as follows:

Consider the simple double pendulum with torque actuation at both joints and all of the mass concentrated in two points (for simplicity). Using q=[θ1,θ2]T\mathbf{q} = [\theta_1,\theta_2]^T, and p1,p2\mathbf{p}_1,\mathbf{p}_2 to denote the locations of m1,m2m_1,m_2.

simple_double_pend.svg


What are the p1,p2\mathbf{p}_1,\mathbf{p}_2?

🗣Answer Let’s tackle the p1\mathbf{p}_1 first. Viewed in the Cartesian coordinates, p1\mathbf{p}_1 is defined as:

p1=[l1sin(θ1)l1cos(θ1)].\mathbf{p}_1 = \begin{bmatrix} l_1 \sin(\theta_1) \\ -l_1\cos(\theta_1) \end{bmatrix}.

The p2\mathbf{p}_2 is attached to p1\mathbf{p}_1, so we can simply add the relative position of the second link:

p2=p1+[l2sin(θ1+θ2)l2cos(θ1+θ2)].\mathbf{p}_2 = \mathbf{p}_1 + \begin{bmatrix} l_2 \sin(\theta_1 + \theta_2) \\ -l_2\cos(\theta_1+\theta_2) \end{bmatrix}.

What are the velocities p˙1,p˙2\dot{\mathbf{p}}_1,\dot{\mathbf{p}}_2 ?

🗣Answer

Let’s find p˙1\dot{\mathbf{p}}_1 first by taking the time derivative:

p˙1=ddtp1=[l1θ1˙cos(θ1)l1θ1˙sin(θ1)].\dot{\mathbf{p}}_1 = \frac{d}{dt}\mathbf{p}_1 = \begin{bmatrix} l_1\dot{\theta_1} \cos(\theta_1) \\ l_1\dot{\theta_1}\sin(\theta_1) \end{bmatrix}.

This requires the chain rule. Because sin(θ1)\sin(\theta_1) is a function of θ1\theta_1, and θ1\theta_1 is a function of time tt, taking the derivative with respect to tt means treating θ1\theta_1 as a composite function. Think of it like this standard form:

dwdt=dwdxdxdt{dw\over dt}={dw\over dx}\cdot{dx\over dt}

Here, w=sin(θ1)w = \sin(\theta_1) and x=θ1(t)x = \theta_1(t). When we differentiate sin(θ1)\sin(\theta_1) with respect to time, we get:

ddtsin(θ1)=dsin(θ1)dθ1dθ1dt=cos(θ1)θ˙1\frac{d}{dt}\sin(\theta_1) = \frac{d\sin(\theta_1)}{d\theta_1} \cdot \frac{d\theta_1}{dt} = \cos(\theta_1) \cdot \dot{\theta}_1

Now let’s tackle p˙2\dot{\mathbf{p}}_2:

p2˙=p1˙+[l2(θ1˙+θ2˙)cos(θ1+θ2)l2(θ1˙+θ2˙)sin(θ1+θ2)].\dot{\mathbf{p}_2} = \dot{\mathbf{p}_1} + \begin{bmatrix} l_2(\dot{\theta_1} + \dot{\theta_2}) \cos(\theta_1 + \theta_2) \\ l_2(\dot{\theta_1} + \dot{\theta_2})\sin(\theta_1+\theta_2) \end{bmatrix}.

What is the Kinetic Energy TT ?

🗣Answer

To use the Euler-Lagrange equation, we first need to find TT. We know the standard kinetic energy equation is

T=12mv2.T = \frac{1}{2}mv^2.

For 2 masses, this translates to:

T=12m1p˙1Tp˙1+12m2p˙2Tp˙2.T = \frac{1}{2} m_1 \dot{\bf p}_1^T \dot{\bf p}_1 + \frac{1}{2} m_2 \dot{\bf p}_2^T \dot{\bf p}_2 .

Notice the matrix trick here: v2v^2 is represented as the dot product p˙Tp˙\dot{\mathbf{p}}^T \dot{\mathbf{p}}. Let’s solve for the first mass:

p˙1Tp˙1=[l1θ1˙cos(θ1)l1θ1˙sin(θ1)][l1θ1˙cos(θ1)l1θ1˙sin(θ1)]=l12θ12˙cos2(θ1)+l12θ12˙sin2(θ1)=l12θ12˙\begin{align} \dot{\bf p}_1^T \dot{\bf p}_1 &= \begin{bmatrix} l_1\dot{\theta_1} \cos(\theta_1) & l_1\dot{\theta_1}\sin(\theta_1) \end{bmatrix} \begin{bmatrix} l_1\dot{\theta_1} \cos(\theta_1) \\ l_1\dot{\theta_1}\sin(\theta_1) \end{bmatrix} \\ &= l_1^2\dot{\theta_1^2}\cos^2(\theta_1) + l_1^2\dot{\theta_1^2}\sin^2(\theta_1) \\ &= l_1^2\dot{\theta_1^2} \end{align}

Next, we expand p˙2Tp˙2\dot{\bf p}_2^T \dot{\bf p}_2:

p˙2Tp˙2=(l1θ˙1cos(θ1)+l2(θ˙1+θ˙2)cos(θ1+θ2))2+(l1θ˙1sin(θ1)+l2(θ˙1+θ˙2)sin(θ1+θ2))2=(l1θ˙1cos(θ1))2Term A+2l1θ˙1cos(θ1)l2(θ˙1+θ˙2)cos(θ1+θ2)Cross term X+(l2(θ˙1+θ˙2)cos(θ1+θ2))2Term B+(l1θ˙1sin(θ1))2Term C+2l1θ˙1sin(θ1)l2(θ˙1+θ˙2)sin(θ1+θ2)Cross term Y+(l2(θ˙1+θ˙2)sin(θ1+θ2))2Term D=l12θ˙12cos2(θ1)+2l1l2θ˙1(θ˙1+θ˙2)cos(θ1)cos(θ1+θ2)+l22(θ˙1+θ˙2)2cos2(θ1+θ2)+l12θ˙12sin2(θ1)+2l1l2θ˙1(θ˙1+θ˙2)sin(θ1)sin(θ1+θ2)+l22(θ˙1+θ˙2)2sin2(θ1+θ2)=l12θ˙12(cos2(θ1)+sin2(θ1))Use: cos2α+sin2α=1+l22(θ˙1+θ˙2)2(cos2(θ1+θ2)+sin2(θ1+θ2))Use: cos2β+sin2β=1+2l1l2θ˙1(θ˙1+θ˙2)(cos(θ1)cos(θ1+θ2)+sin(θ1)sin(θ1+θ2))Use: cos(αβ)=cosαcosβ+sinαsinβ=l12θ˙12\cancelto1(cos2(θ1)+sin2(θ1))+l22(θ˙1+θ˙2)2\cancelto1(cos2(θ1+θ2)+sin2(θ1+θ2))+2l1l2θ˙1(θ˙1+θ˙2)cos(θ1(θ1+θ2))α=θ1,β=θ1+θ2=l12θ˙12+l22(θ˙1+θ˙2)2+2l1l2θ˙1(θ˙1+θ˙2)cos(θ1θ1θ2)=l12θ˙12+l22(θ˙1+θ˙2)2+2l1l2θ˙1(θ˙1+θ˙2)cos(θ2)\begin{align} \dot{\mathbf{p}}_2^T \dot{\mathbf{p}}_2 &= \left( l_1\dot{\theta}_1 \cos(\theta_1) +l_2(\dot{\theta}_1 + \dot{\theta}_2) \cos(\theta_1 + \theta_2) \right)^2 + \left( l_1\dot{\theta}_1\sin(\theta_1) +l_2(\dot{\theta}_1 + \dot{\theta}_2)\sin(\theta_1+\theta_2) \right)^2 \\[10pt] &= \underbrace{\left(l_1\dot{\theta}_1 \cos(\theta_1)\right)^2}_{\text{Term A}} + \underbrace{2 \cdot l_1\dot{\theta}_1 \cos(\theta_1) \cdot l_2(\dot{\theta}_1 + \dot{\theta}_2) \cos(\theta_1 + \theta_2)}_{\text{Cross term X}} + \underbrace{\left(l_2(\dot{\theta}_1 + \dot{\theta}_2) \cos(\theta_1 + \theta_2)\right)^2}_{\text{Term B}} \\[4pt] &\quad + \underbrace{\left(l_1\dot{\theta}_1\sin(\theta_1)\right)^2}_{\text{Term C}} + \underbrace{2 \cdot l_1\dot{\theta}_1\sin(\theta_1) \cdot l_2(\dot{\theta}_1 + \dot{\theta}_2)\sin(\theta_1+\theta_2)}_{\text{Cross term Y}} + \underbrace{\left(l_2(\dot{\theta}_1 + \dot{\theta}_2)\sin(\theta_1+\theta_2)\right)^2}_{\text{Term D}} \\[10pt] &= l_1^2\dot{\theta}_1^2\cos^2(\theta_1) + 2l_1l_2\dot{\theta}_1(\dot{\theta}_1 + \dot{\theta}_2)\cos(\theta_1)\cos(\theta_1+\theta_2) + l_2^2(\dot{\theta}_1 + \dot{\theta}_2)^2\cos^2(\theta_1+\theta_2) \\[4pt] &\quad + l_1^2\dot{\theta}_1^2\sin^2(\theta_1) + 2l_1l_2\dot{\theta}_1(\dot{\theta}_1 + \dot{\theta}_2)\sin(\theta_1)\sin(\theta_1+\theta_2) + l_2^2(\dot{\theta}_1 + \dot{\theta}_2)^2\sin^2(\theta_1+\theta_2) \\[10pt] &= \underbrace{l_1^2\dot{\theta}_1^2\Big(\cos^2(\theta_1) + \sin^2(\theta_1)\Big)}_{\text{Use: }\cos^2\alpha + \sin^2\alpha = 1} + \underbrace{l_2^2(\dot{\theta}_1 + \dot{\theta}_2)^2\Big(\cos^2(\theta_1+\theta_2) + \sin^2(\theta_1+\theta_2)\Big)}_{\text{Use: }\cos^2\beta + \sin^2\beta = 1} \\[4pt] &\quad + \underbrace{2l_1l_2\dot{\theta}_1(\dot{\theta}_1 + \dot{\theta}_2)\Big(\cos(\theta_1)\cos(\theta_1+\theta_2) + \sin(\theta_1)\sin(\theta_1+\theta_2)\Big)}_{\text{Use: }\cos(\alpha-\beta) = \cos\alpha\cos\beta + \sin\alpha\sin\beta} \\[10pt] &= l_1^2\dot{\theta}_1^2 \cdot \cancelto{1}{\Big(\cos^2(\theta_1) + \sin^2(\theta_1)\Big)} + l_2^2(\dot{\theta}_1 + \dot{\theta}_2)^2 \cdot \cancelto{1}{\Big(\cos^2(\theta_1+\theta_2) + \sin^2(\theta_1+\theta_2)\Big)} \\[4pt] &\quad + 2l_1l_2\dot{\theta}_1(\dot{\theta}_1 + \dot{\theta}_2) \cdot \underbrace{\cos\Big(\theta_1 - (\theta_1+\theta_2)\Big)}_{\alpha = \theta_1,\, \beta = \theta_1+\theta_2} \\[10pt] &= l_1^2\dot{\theta}_1^2 + l_2^2(\dot{\theta}_1 + \dot{\theta}_2)^2 + 2l_1l_2\dot{\theta}_1(\dot{\theta}_1 + \dot{\theta}_2)\cos(\cancel{\theta_1} - \cancel{\theta_1} - \theta_2) \\[10pt] &= \boxed{l_1^2\dot{\theta}_1^2 + l_2^2(\dot{\theta}_1 + \dot{\theta}_2)^2 + 2l_1l_2\dot{\theta}_1(\dot{\theta}_1 + \dot{\theta}_2)\cos(\theta_2)} \end{align}
Remark

The preceding derivation uses the following trigonometric identities:

  • cos2α+sin2α=1\cos^2\alpha + \sin^2\alpha = 1
  • cos(αβ)=cosαcosβ+sinαsinβ\cos(\alpha-\beta) = \cos\alpha\cos\beta + \sin\alpha\sin\beta
  • cos(θ)=cos(θ)\cos(-\theta) = \cos(\theta)

Let’s wrap up TT by plugging these back into the kinetic energy formula:

T=12m1p˙1Tp˙1+12m2p˙2Tp˙2=12m1l12θ12˙+12m2(l12θ˙12+l22(θ˙1+θ˙2)2+2l1l2θ˙1(θ˙1+θ˙2)cos(θ2))=12(m1+m2)l12θ˙12+12m2l22(θ˙1+θ˙2)2+m2l1l2θ˙1(θ˙1+θ˙2)cos(θ2)\begin{align} T &= \frac{1}{2} m_1 \dot{\bf p}_1^T \dot{\bf p}_1 + \frac{1}{2} m_2 \dot{\bf p}_2^T \dot{\bf p}_2\\ &= \frac{1}{2} m_1 l_1^2\dot{\theta_1^2} + \frac{1}{2} m_2 (l_1^2\dot{\theta}_1^2 + l_2^2(\dot{\theta}_1 + \dot{\theta}_2)^2 + 2l_1l_2\dot{\theta}_1(\dot{\theta}_1 + \dot{\theta}_2)\cos(\theta_2)) \\ =& \frac{1}{2}(m_1 + m_2) l_1^2 \dot{\theta}_1^2 + \frac{1}{2} m_2 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2)^2 + m_2 l_1 l_2 \dot{\theta}_1 (\dot{\theta}_1 + \dot{\theta}_2) \cos(\theta_2) \end{align}

What is the Potential Engergy UU?

🗣Answer For potential energy from gravity, the standard expression is

U=mgh.U = mgh.

The height for each mass can be easily found using trigonometric function:

U=m1gy1+m2gy2=m1gl1cos(θ1)m2g(l1cos(θ1)+l2cos(θ1+θ2))=m1gl1cos(θ1)m2gl1cos(θ1)m2gl2cos(θ1+θ2)=(m1+m2)gl1cos(θ1)m2gl2cos(θ1+θ2)\begin{align} U &= m_1 g y_1 + m_2 g y_2 \\ &= -m_1 g l_1\cos(\theta_1) - m_2g\bigg(l_1 \cos(\theta_1) + l_2\cos(\theta_1 + \theta_2)\bigg) \\ &= -m_1 g l_1\cos(\theta_1) - m_2g l_1 \cos(\theta_1) - m_2g l_2\cos(\theta_1 + \theta_2) \\ &= -(m_1 + m_2) g l_1 \cos(\theta_1) - m_2g l_2\cos(\theta_1 + \theta_2) \end{align}

Applying the Euler-Lagrange Equation

In Lagrangian mechanics, the Lagrangian is defined as

L=TU,L = T - U,

The Euler-Lagrange equation dictates the dynamics:

ddt(Lq˙i)Lqi=τi.\frac{d}{dt}\left(\frac{\partial L}{\partial \dot{q}_i}\right) - \frac{\partial L}{\partial q_i} = \tau_i.

Because our expressions are complicated, separating TT and UU keeps the calculus much cleaner:

ddt(Tq˙iUq˙i)(TqiUqi)=τi.\frac{d}{dt}\left(\frac{\partial T}{\partial \dot{q}_i} - \frac{\partial U}{\partial \dot{q}_i}\right) - \left(\frac{\partial T}{\partial q_i} - \frac{\partial U}{\partial q_i}\right) = \tau_i.

Solving for Torque τ1\tau_1

Let’s systematically derive the equation for τ1\tau_1:

ddt(Tθ˙1Uθ˙1)(Tθ1Uθ1)=τ1,\frac{d}{dt}\left(\frac{\partial T}{\partial \dot{\theta}_1} - \frac{\partial U}{\partial \dot{\theta}_1}\right) - \left(\frac{\partial T}{\partial \theta_1} - \frac{\partial U}{\partial \theta_1}\right) = \tau_1,

given

T=12(m1+m2)l12θ˙12+12m2l22(θ˙1+θ˙2)2+m2l1l2θ˙1(θ˙1+θ˙2)cos(θ2),U=(m1+m2)gl1cos(θ1)m2gl2cos(θ1+θ2).\begin{align} T &= \frac{1}{2}(m_1 + m_2) l_1^2 \dot{\theta}_1^2 + \frac{1}{2} m_2 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2)^2 + m_2 l_1 l_2 \dot{\theta}_1 (\dot{\theta}_1 + \dot{\theta}_2) \cos(\theta_2),\\ U &= -(m_1 + m_2) g l_1 \cos(\theta_1) - m_2g l_2\cos(\theta_1 + \theta_2). \end{align}

📌calculate Uθ˙1\displaystyle \frac{\partial U}{\partial \dot{\theta}_1}

Since there is no θ˙1\dot{\theta}_1 in UU, this term is simply:

Uθ˙1=0.\frac{\partial U}{\partial \dot{\theta}_1}=0.

📌calculate Tθ1\displaystyle \frac{\partial T}{\partial {\theta}_1}

Since there is no θ1{\theta}_1 in TT, the term is also

Tθ1=0.\frac{\partial T}{\partial {\theta}_1} = 0.

📌calculate Uθ1\displaystyle \frac{\partial U}{\partial \theta_1}

Treat θ2\theta_2 as a constant. The derivative of cos(x)\cos(x) is sin(x)-\sin(x), and the chain rule for the inside of (θ1+θ2)(\theta_1 + \theta_2) with respect to θ1\theta_1 is just 11!

Uθ1=(m1+m2)gl1sin(θ1)+m2gl2sin(θ1+θ2)(θ1+θ2)=(m1+m2)gl1sin(θ1)+m2gl2sin(θ1+θ2)(1)=(m1+m2)gl1sin(θ1)+m2gl2sin(θ1+θ2)\begin{align} \frac{\partial U}{\partial \theta_1} &= (m1 + m_2)gl_1 \sin(\theta_1) + m_2 g l_2 \sin(\theta_{1}+\theta_{2})\cdot(\theta_{1}+\theta_{2})' \tag{chain rule} \\ &= (m1 + m_2)gl_1 \sin(\theta_1) + m_2 g l_2 \sin(\theta_{1}+\theta_{2})\cdot(1) \\ &= (m1 + m_2)gl_1 \sin(\theta_1) + m_2 g l_2 \sin(\theta_{1}+\theta_{2}) \\ \end{align}

📌calculate Tθ˙1\displaystyle \frac{\partial T}{\partial \dot{\theta}_1}

Tθ˙1=θ˙1(12(m1+m2)l12θ˙121+12m2l22(θ˙1+θ˙2)22+m2l1l2θ˙1(θ˙1+θ˙2)cos(θ2)3)\begin{align} \frac{\partial T}{\partial \dot{\theta}_1} &=\frac{\partial}{\partial \dot{\theta}_1} \left( \underbrace {\frac{1}{2}(m_1 + m_2) l_1^2 \dot{\theta}_1^2}_\text{1} + \underbrace{\frac{1}{2} m_2 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2)^2}_\text{2} + \underbrace{m_2 l_1 l_2 \dot{\theta}_1 (\dot{\theta}_1 + \dot{\theta}_2) \cos(\theta_2)}_\text{3} \right) \end{align}

(1) first term:

θ˙1(12(m1+m2)l12θ˙12)=(m1+m2)l12θ˙1\begin{align} \frac{\partial}{\partial \dot{\theta}_1} (\frac{1}{2}(m_1 + m_2) l_1^2 \dot{\theta}_1^2) &= (m_1+m_2)l_1^2 \dot{\theta}_1 \end{align}

(2) second term:

θ˙1(12m2l22(θ˙1+θ˙2)2)=m2l22(θ˙1+θ˙2)(θ˙1+θ˙2)=m2l22(θ˙1+θ˙2)\begin{align} \frac{\partial}{\partial \dot{\theta}_1} (\frac{1}{2} m_2 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2)^2) &= m_2 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2) \cdot (\dot{\theta}_1 + \dot{\theta}_2)' \tag{chain rule}\\ &= m_2 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2) \end{align}

(3) third term:

We can treat m2l1l2cos(θ2)m_2 l_1 l_2 \cos(\theta_2) as constant multiplier. We only need the product rule ddt(uv)=u˙v+uv˙\displaystyle \frac{d}{dt}(u \cdot v) = \dot{u}v + u\dot{v} for θ˙1(θ˙1+θ˙2)\dot{\theta}_1 (\dot{\theta}_1 + \dot{\theta}_2):

θ˙1(m2l1l2θ˙1(θ˙1+θ˙2)cos(θ2))=m2l1l2cos(θ2)(1(θ˙1+θ˙2)+θ˙11)=m2l1l2cos(θ2)(2θ˙1+θ˙2)\begin{align} \frac{\partial}{\partial \dot{\theta}_1} (m_2 l_1 l_2 \dot{\theta}_1 (\dot{\theta}_1 + \dot{\theta}_2) \cos(\theta_2)) &= m_2 l_1 l_2 \cos(\theta_2) \cdot \left(1\cdot(\dot{\theta}_1 + \dot{\theta}_2)+\dot{\theta}_1\cdot1\right) \\ &= m_2 l_1 l_2 \cos(\theta_2) (2\dot{\theta}_1 + \dot{\theta}_2) \end{align}

(4) together:

Putting it all together, we get:

Tθ˙1=(m1+m2)l12θ˙1+m2l22(θ˙1+θ˙2)+m2l1l2(2θ˙1+θ˙2)cos(θ2)\begin{align} \frac{\partial T}{\partial \dot{\theta}_1} &= (m_1 + m_2)l_1^2 \dot{\theta}_1 + m_2 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2) + m_2 l_1 l_2 (2\dot{\theta}_1 + \dot{\theta}_2) \cos(\theta_2) \end{align}

📌 Summarizing Our Progress

We have the following

  • Uθ˙1=0\displaystyle \frac{\partial U}{\partial \dot{\theta}_1}=0
  • Tθ1=0\displaystyle \frac{\partial T}{\partial {\theta}_1} = 0
  • Uθ1=(m1+m2)gl1sin(θ1)+m2gl2sin(θ1+θ2)\displaystyle \frac{\partial U}{\partial \theta_1} = (m1 + m_2)gl_1 \sin(\theta_1) + m_2 g l_2 \sin(\theta_{1}+\theta_{2})
  • Tθ˙1=(m1+m2)l12θ˙1+m2l22(θ˙1+θ˙2)+m2l1l2(2θ˙1+θ˙2)cos(θ2)\displaystyle \frac{\partial T}{\partial \dot{\theta}_1} = (m_1 + m_2)l_1^2 \dot{\theta}_1 + m_2 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2) + m_2 l_1 l_2 (2\dot{\theta}_1 + \dot{\theta}_2) \cos(\theta_2)

Therefore, the

ddt(Tθ˙1Uθ˙1)(Tθ1Uθ1)=τ1\frac{d}{dt}\left(\frac{\partial T}{\partial \dot{\theta}_1} - \frac{\partial U}{\partial \dot{\theta}_1}\right) - \left(\frac{\partial T}{\partial \theta_1} - \frac{\partial U}{\partial \theta_1}\right) = \tau_1

could be simplified to

ddt(Tθ˙1Uθ˙1)(Tθ1Uθ1)=τ1,ddtTθ˙1+Uθ1=τ1\begin{align} \frac{d}{dt}\left(\frac{\partial T}{\partial \dot{\theta}_1} - \cancel{\frac{\partial U}{\partial \dot{\theta}_1}}\right) - \left(\cancel{\frac{\partial T}{\partial \theta_1}} - \frac{\partial U}{\partial \theta_1}\right) &= \tau_1, \\ \frac{d}{dt}\frac{\partial T}{\partial \dot{\theta}_1} + \frac{\partial U}{\partial \theta_1} = \tau_1 \end{align}

The last hurdle is calculating the time derivative:

ddtTθ˙1.\frac{d}{dt}\frac{\partial T}{\partial \dot{\theta}_1}.

📌calculate ddtTθ˙1\displaystyle \frac{d}{dt}\frac{\partial T}{\partial \dot{\theta}_1}

ddtTθ˙1=ddt((m1+m2)l12θ˙1+m2l22(θ˙1+θ˙2)+m2l1l2(2θ˙1+θ˙2)cos(θ2))=(m1+m2)l12θ¨1+m2l22(θ¨1+θ¨2)+m2l1l2(2θ˙1+θ˙2)cos(θ2)+m2l1l2(2θ˙1+θ˙2)cos(θ2)=(m1+m2)l12θ¨1+m2l22(θ¨1+θ¨2)+m2l1l2(2θ¨1+θ¨2)cos(θ2)m2l1l2(2θ˙1+θ˙2)sin(θ2)θ2˙\begin{align} \frac{d}{dt}\frac{\partial T}{\partial \dot{\theta}_1} & = \frac{d}{dt} \left((m_1 + m_2)l_1^2 \dot{\theta}_1 + m_2 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2) + m_2 l_1 l_2 (2\dot{\theta}_1 + \dot{\theta}_2) \cos(\theta_2)\right) \\ &= (m_1 + m_2)l_1^2 \ddot{\theta}_1 + m_2 l_2^2 (\ddot{\theta}_1 + \ddot{\theta}_2) + m_2 l_1 l_2 (2\dot{\theta}_1 + \dot{\theta}_2) '\cos(\theta_2) + m_2 l_1 l_2 (2\dot{\theta}_1 + \dot{\theta}_2) \cos'(\theta_2) \\ &= (m_1 + m_2)l_1^2 \ddot{\theta}_1 + m_2 l_2^2 (\ddot{\theta}_1 + \ddot{\theta}_2) + m_2 l_1 l_2 (2\ddot{\theta}_1 + \ddot{\theta}_2) \cos(\theta_2) - m_2 l_1 l_2 (2\dot{\theta}_1 + \dot{\theta}_2) \sin(\theta_2)\dot{\theta_2} \end{align}

The last term requires both

  • product rule: ddt(uv)=u˙v+uv˙\displaystyle \frac{d}{dt}(u \cdot v) = \dot{u}v + u\dot{v}.
  • chain rule: dwdt=dwdxdxdt\displaystyle {dw\over dt}={dw\over dx}\cdot{dx\over dt}

📌 Final Equation for τ1\tau_1

τ1= (m1+m2)l12θ¨1+m2l22(θ¨1+θ¨2)+m2l1l2((2θ¨1+θ¨2)cos(θ2)(2θ˙1+θ˙2)sin(θ2)θ˙2)+(m1+m2)gl1sin(θ1)+m2gl2sin(θ1+θ2)\begin{align} \tau_1 =& \ (m_1 + m_2)l_1^2 \ddot{\theta}_1 + m_2 l_2^2 (\ddot{\theta}_1 + \ddot{\theta}_2) + m_2 l_1 l_2 \Big((2\ddot{\theta}_1 + \ddot{\theta}_2) \cos(\theta_2) - (2\dot{\theta}_1 + \dot{\theta}_2) \sin(\theta_2)\dot{\theta}_2\Big) \\ &+ (m_1 + m_2)gl_1 \sin(\theta_1) + m_2 g l_2 \sin(\theta_1+\theta_2) \end{align}

We can calculate τ2\tau_2 using the exact same workflow to yield:

τ2=m2l22(θ¨1+θ¨2)+m2l1l2θ¨1cos(θ2)+m2l1l2θ˙12sin(θ2)+m2gl2sin(θ1+θ2).\tau_2 = m_2 l_2^2 (\ddot{\theta}_1 + \ddot{\theta}_2) + m_2 l_1 l_2 \ddot{\theta}_1 \cos(\theta_2) + m_2 l_1 l_2 \dot{\theta}_1^2 \sin(\theta_2) + m_2 g l_2 \sin(\theta_{1}+\theta_2).

See also...