2

Introduction

I'd like to preface this by saying that while I'm a reasonably competent developer, my calculus skills leave a lot to be desired.

I've been reading up on basic physics, and I thought I had a grip on the behaviour of the Lagrangian formulation of physics, but it turns out there is something I just don't understand, which is why I'm turning to this place for assistance.

I've been simulating various systems like pendulums, gravitational systems, etc and my very simplistic approach has worked fine. However, when I tried it on the double pendulum, I'm not getting the expected results.

Calculating the Lagrangian

I'm assuming the coordinates of the masses:

$$ \begin{align} x_1 &= sin(θ_1)\,l_1 \\ x_2 &= x_1 + sin(θ_2)\,l_2 \\ y_1 &= -cos(θ_1)\,l_1 \\ y_2 &= y_1 - cos(θ_2)\,l_2 \end{align} $$

I then use Maxima to compute the Lagrangian, which is:

$$ {{2\,l_{1}\,l_{2}\,m_{2}\,\dot{θ}_{1}\,\dot{θ}_{2}\,\sin θ_{1}\,\sin θ_{2}+ \left(2\,l_{1}\,l_{2}\,m_{2}\,\dot{θ}_{1}\,\dot{θ}_{2}\,\cos θ_{1}+2\,g\,l_{2}\, m_{2}\right)\,\cos θ_{2}+\left(2\,g\,l_{1}\,m_{2}+2\,g\,l_{1}\,m_{1} \right)\,\cos θ_{1}+l_{2}^2\,m_{2}\,\dot{θ}_{2}^2+\left(l_{1}^2\,m_{2}+ l_{1}^2\,m_{1}\right)\,\dot{θ}_{1}^2}\over{2}} $$

I then use the Euler-Lagrange equation to give me the solution for the first coordinate:

$$ \ddot{θ}_1 = -{{\left(\ddot{θ}_{2}\,l_{2}\,m_{2}\,\sin θ_{1}-l_{2}\,m_{2}\,\dot{θ}_{2}^2\, \cos θ_{1}\right)\,\sin θ_{2}+\left(l_{2}\,m_{2}\,\dot{θ}_{2}^2\,\sin θ_{1}+\ddot{θ}_{2}\,l_{2}\,m_{2}\,\cos θ_{1}\right)\,\cos θ_{2}+\left(g\, m_{2}+g\,m_{1}\right)\,\sin θ_{1}}\over{l_{1}\,m_{2}+l_{1}\,m_{1}}} $$

And the solution for the second coordinate:

$$ \ddot{θ}_2 = -{{\left(\ddot{θ}_{1}\,l_{1}\,\sin θ_{1}+l_{1}\,\dot{θ}_{1}^2\,\cos θ_{1}+g \right)\,\sin θ_{2}+\left(\ddot{θ}_{1}\,l_{1}\,\cos θ_{1}-l_{1}\,\dot{θ}_{1}^2\, \sin θ_{1}\right)\,\cos θ_{2}}\over{l_{2}}} $$

While my Lagrangian looks a bit different from the typical one I can find when searching online for the Lagrangian for a double pendulum, they do seem to be equivalent, and I did try to enter the one I found online and I get the same numbers from that one.

Trying to simulate the motion

Once I got this, I wanted to simulate it in the same simplistic manner as I have have simulated other physical systems, by accumulating the positions and velocities.

For each iteration, I compute 6 variables like so:

$$ \texttt{thetadotdot_1 = } \ddot{\theta}_1 \Delta t \texttt{ /* The result above */} \\ \texttt{thetadotdot_2 = } \ddot{\theta}_2 \Delta t \texttt{ /* The result above */} \\ \texttt{thetadot_1 = thetadot_1 + thetadotdot_1} \\ \texttt{thetadot_2 = thetadot_2 + thetadotdot_2} \\ \texttt{theta_1 = theta_1 + thetadot_1} \\ \texttt{theta_2 = theta_2 + thetadot_1} $$

I then draw the two objects based on theta_1 and theta_2 alogn with the values of $l_1$ and $l_2$.

The problem I am facing is that while the two objects swings back and forth, they do so completely independently. Each one swings like a regular pendulum, without being influenced by the other. The fact that they swing at all suggests that the way I approach the problem isn't entirely wrong, but I clearly made a mistake somewhere.

I'd be very happy is someone could point out where my mistake is?

  • 2
    Your last four expressions should be of the form $a = a_{current} + a_{dot} \Delta t$. Add the time step and see if that changes anything. – aghostinthefigures Dec 01 '20 at 13:47
  • You should see that you get a circular dependency in the second deriatives. How to formulate a first-order system while solving the linear system for the second derivatives I demonstrated in https://math.stackexchange.com/questions/2084922/transform-the-double-pendulum-differential-equations-into-a-first-order-system/2084996#2084996 – Lutz Lehmann Dec 01 '20 at 18:23
  • How did you determine how the pendulums swing back-and-forth? Did you properly chain the pendulums, that is, set $x_2=l_1\sin(\theta_1)+l_2\sin(\theta_2)$ etc.? – Lutz Lehmann Dec 01 '20 at 18:27
  • Your $\ddot \theta_1$ explicitely depends on $\ddot \theta_2$ and so does $\ddot \theta_2$. While this should not affect the explicit Euler's method you're using (with $\Delta t = 1$, the time step might be quite large for an accurate simulation), the proper way is to bring the equations to the form (no second derivatives on the right) $$ \ddot \theta_1 = f_1(\theta_1, \theta_2, \dot \theta_1, \dot \theta_2)\ \ddot \theta_2 = f_2(\theta_1, \theta_2, \dot \theta_1, \dot \theta_2) $$ – uranix Dec 01 '20 at 22:00
  • Thank you. I actually multiply $\ddot{\theta}$ with $\Delta t$, but I never included it in my question. I will update the text to reflect this. – Elias Mårtenson Dec 02 '20 at 03:48
  • @LutzLehmann I did it by drawing the positions of the masses and running the simulation. I'm not sure it's possible to include a video clip in a stackexchange question? In any case, as you suggested, I am indeed using that formula for the x and y positions of the masses. – Elias Mårtenson Dec 02 '20 at 03:50
  • @uranix I think the last part of your message is the the thing I don't understand. I've searched a bit and I haven't found any clear information how to actually bring these equations into the form you mentioned. – Elias Mårtenson Dec 02 '20 at 04:19
  • @EliasMårtenson Now you have a pair of equations for $\ddot \theta_1$ and $\ddot \theta_2$. Both they have $\ddot \theta_1$ and $\ddot \theta_2$ in their right hand side. You need to treat them like a system of equatons and solve it for $\ddot \theta_1$ and $\ddot \theta_2$. Then you'll get an explicit form of the ODE (this is the form that numerical methods are usually written for) – uranix Dec 02 '20 at 09:40
  • You need to apply the time step to all updates, $\dot\theta^{k+1}=\dot\theta^k+\ddot\theta^k\Delta t$, $\theta^{k+1}=\theta^k+\dot\theta^k\Delta t$. – Lutz Lehmann Dec 02 '20 at 10:26

1 Answers1

1

The Lagrangian has the traditional form $L=T-V$ of difference of kinetic and potential energy. $\newcommand{\pd}[2]{\frac{\partial#1}{\partial#2}}$ \begin{align} T&=\frac{m_1}{2}(\dot x_1^2+\dot y_1^2)+\frac{m_2}{2}(\dot x_2^2+\dot y_2^2) \\ &=\frac{m_1}{2}l_1^2\dot\theta_1^2+\frac{m_2}{2}\Bigl(l_1^2\dot\theta_1^2+2l_1l_2\cos(\theta_1-\theta_2)\dot\theta_1\dot\theta_2+l_2^2\dot\theta_2^2\Bigr) \\ V&=m_1gy_1+m_2gy_2 \\ &=-(m_1+m_2)l_1g\cos\theta_1-m_2l_2\cos\theta_2 \end{align} with partial derivatives \begin{align} \pd{L}{\dot\theta_1}=\pd{T}{\dot\theta_1} &=(m_1+m_2)l_1^2\dot\theta_1+m_2l_1l_2\cos(\theta_1-\theta_2)\dot\theta_2 \\ \pd{L}{\dot\theta_2}=\pd{T}{\dot\theta_2} &=m_2l_1l_2\cos(\theta_1-\theta_2)\dot\theta_1+m_2l_2^2\dot\theta_2 \\ \pd{L}{\theta_1}&=-m_2l_1l_2\sin(\theta_1-\theta_2)\dot\theta_1\dot\theta_2-(m_1+m_2)l_1g\sin\theta_1 \\ \pd{L}{\theta_2}&=m_2l_1l_2\sin(\theta_1-\theta_2)\dot\theta_1\dot\theta_2-m_2l_2g\sin\theta_2 \end{align} and Euler-Lagrange equations \begin{align} \frac{d}{dt}\pd{L}{\dot\theta_1}=\pd{L}{\theta_1}&\implies \\ (m_1+m_2)l_1^2\ddot\theta_1+m_2l_1l_2\cos(\theta_1-\theta_2)\ddot\theta_2 &=-m_2l_1l_2\sin(\theta_1-\theta_2)\dot\theta_2^2-(m_1+m_2)l_1g\sin\theta_1 \\ \frac{d}{dt}\pd{L}{\dot\theta_2}=\pd{L}{\theta_2}&\implies \\ m_2l_1l_2\cos(\theta_1-\theta_2)\ddot\theta_1+m_2l_2^2\ddot\theta_2 &=m_2l_1l_2\sin(\theta_1-\theta_2)\dot\theta_1^2-m_2l_2g\sin\theta_2 \end{align}

This now is a nice linear system for the second derivatives $$ \begin{bmatrix} (m_1+m_2)&m_2\cos(\theta_1-\theta_2)\\ m_2\cos(\theta_1-\theta_2)&m_2 \end{bmatrix} \begin{bmatrix} l_1\ddot\theta_1\\l_2\ddot\theta_2 \end{bmatrix} = \begin{bmatrix} -m_2l_2\sin(\theta_1-\theta_2)\dot\theta_2^2-(m_1+m_2)g\sin\theta_1 \\ m_2l_1\sin(\theta_1-\theta_2)\dot\theta_1^2-m_2g\sin\theta_2 \end{bmatrix} $$ or after division by $m_2$, setting $\mu=1+\frac{m_1}{m_2}$, $$ \begin{bmatrix} \mu&\cos(\theta_1-\theta_2)\\ \cos(\theta_1-\theta_2)&1 \end{bmatrix} \begin{bmatrix} l_1\ddot\theta_1\\l_2\ddot\theta_2 \end{bmatrix} =- \begin{bmatrix} \mu g\sin\theta_1+l_2\sin(\theta_1-\theta_2)\dot\theta_2^2 \\ g\sin\theta_2-l_1\sin(\theta_1-\theta_2)\dot\theta_1^2 \end{bmatrix} $$ This can be solved via manual elimination, the Cramer formula/multiplication with the adjoint matrix, or a linear system solver.

Lutz Lehmann
  • 131,652
  • Those variables come from a mistake when translating the equation for this post. I used those names in Maxima for $\dot{\theta}$ and $\ddot{\theta}$., since they were easier to type. I then exported the equation as LaTeX and manually changed the names. I'll update the post to reflect this. – Elias Mårtenson Dec 04 '20 at 09:28
  • Now use trigonometric identities like $\cos a\cos b+\sin a\sin b=\cos(a-b)$ to reduce the number of terms, which then makes following and checking the steps easier. – Lutz Lehmann Dec 04 '20 at 09:42