Lagrangian mechanics explanation for Fidello.

In this article, I explain to Fidello from Foci's Discord server some prerequisite knowledge he needs to effectively derive the equations of motion for a double rigid pendulum.

Partial differentiation

Partial derivatives are just a straightforward extension of derivatives as you understand them already. The key difference is that they are derivatives of multivariable functions instead of single-variable functions. Further, when you differentiate with respect to one variable, all other variables are kept constant. If you would like to build a graphical image of what the partial derivative is, well recall that the derivative of a single-variable function is just the gradient of that function. Consequently, it is also the gradient of the tangent line to that function. The partial derivative is similar to that. As when we have a function with more than a single independent variable, we have the freedom to choose which variable or variables we wish to determine our function's gradient with respect to.

If you want to visualize this, imagine a surface defined by z=f(x,y)z=f(x,y) for example. Because a tangent line is two dimensional and we're in three dimensional space, there can be more than one tangent line to a given point. As when constructing the tangent line, we must answer a question: in which direction do we want our line to be tangential to our surface? It could be tangential in the xx direction or the yy direction, or even in any arbitrary direction in the xx-yy plane. If we want the tangent line in the xx direction, we will need the partial derivative with respect to xx to get its gradient, whereas if we want the tangent line in the yy direction, we will need the partial derivative with respect to yy to get its gradient. More generally, for an arbitrary direction in the xx-yy plane we would use the directional derivative as it is called.

Say ff is a function of two variables — xx and yy. Then its partial derivative with respect to xx is formally defined as:

∂f∂x=lim⁡h→0f(x+h,y)−f(x,y)h.\begin{aligned} \dfrac{\partial f}{\partial x} &= \lim_{h\rightarrow 0} \dfrac{f(x+h, y)-f(x, y)}{h}. \end{aligned}

This is analogous to the first principles definition of the derivative you would have learned for standard derivatives. Namely, if we are differentiating f(x)f(x):

wedfdx=lim⁡h→0f(x+h)−f(x)h.\begin{aligned}we \dfrac{df}{dx} &= \lim_{h\rightarrow 0}\dfrac{f(x+h) - f(x)}{h}. \end{aligned}

The only difference is that now we also have a variable yy that our function f(x,y)f(x,y) depends on, but is kept constant when differentiating with respect to xx. Say f(x,y)=2x2yf(x,y)=2x^2y. Then ∂f∂x\dfrac{\partial f}{\partial x} would be:

∂f∂x=lim⁡h→02(x+h)2y−2x2yh.\begin{aligned} \dfrac{\partial f}{\partial x} &= \lim_{h\rightarrow 0} \dfrac{2(x+h)^2y - 2x^2y}{h}. \end{aligned}

Did you notice that 2y2y is a common factor of both terms in our numerator? Let us take it out of our limit altogether, as it is effectively a constant (it doesn't depend on hh, after all).

∂f∂x=2ylim⁡h→0(x+h)2−x2h\begin{aligned} \dfrac{\partial f}{\partial x} &= 2y\lim_{h\rightarrow 0} \dfrac{(x+h)^2-x^2}{h} \end{aligned}

Using the binomial theorem, we know that

(x+h)2=x2+2xh+h2.\begin{aligned} (x+h)^2 &= x^2 + 2xh + h^2. \end{aligned}

Hence:

∂f∂x=2ylim⁡h→0x2+2xh+h2−x2h=2ylim⁡h→02xh+h2h=2ylim⁡h→02x+h=2y⋅2x=4xy.\begin{aligned} \dfrac{\partial f}{\partial x} &= 2y\lim_{h\rightarrow 0} \dfrac{x^2+2xh + h^2-x^2}{h} \\ &= 2y\lim_{h\rightarrow 0} \dfrac{2xh + h^2}{h} \\ &= 2y\lim_{h\rightarrow 0} 2x + h \\ &= 2y \cdot 2x \\ &= 4xy. \end{aligned}

Okay, so that is the long way of finding out partial derivatives. Fortunately, there is also a faster way. Which is that we apply normal differentiation rules, but any variable we are not differentiating with respect to is treated like it's a constant. So for f(x,y)=2x2yf(x,y)=2x^2y we would treat the 2y2y as just a constant number and only differentiate the x2x^2. Applying the power rule, we see that ddxx2=2x\dfrac{d}{dx}x^2 = 2x and hence:

∂f∂x=2y⋅2x=4xy.\begin{aligned} \dfrac{\partial f}{\partial x} &= 2y \cdot 2x \\ &= 4xy. \end{aligned}

Heat equation example

One of the simplest partial differential equations is the heat equation. In its simplest form it is:

∂u∂t=α∂2u∂x2\begin{aligned} \dfrac{\partial u}{\partial t} &= \alpha \dfrac{\partial^2 u}{\partial x^2} \end{aligned}

Where u(x,t)u(x,t) is a function describing the temperature of the one-dimensional object (only one dimensional as the above heat equation only has a single spatial dimension, if we want more spatial dimensions we'll have to add second partial derivatives with respect to those other dimensions, too) we're modelling and α\alpha is some constant. I know this equation may look confusing at first glance, but it is actually saying something rather intuitive to you.

Do you remember from your maths class that the second derivative of a function is its concavity? So if the second derivative is negative, that means our function is concave down — it is leading to some sort of maximum. Whereas if it is positive, the function is concave up, which means it is going up from some minimum. We have the second derivative with respect to space on the right-hand side of Equation (1), so it essentially returns positive if we have a localized colder area and neighbouring hotter points. Whereas it returns negative if we have a really hot point surrounded by cooler points. The left-hand side of Equation (1), however, represents the rate of change of our function in time.

Equation (1) therefore essentially says that if we are in a region where there's a really cold point surrounded by hotter points, the temperature will increase in the short-term for that colder point. Whereas the equation says that the temperature will decrease in a hotter region surrounded by colder points. If you've ever brought something hot out of the oven, or put something of room temperature into the fridge or freezer, this should make intuitive sense to you.

Lagrangian mechanics

Lagrangian mechanics is one of three major formulations of classical mechanics, the others being Newtonian mechanics and Hamiltonian mechanics. Classical mechanics as a whole is a branch of physics most applicable to the situations that humans most often encounter, as it does not account for quantum randomness (hence cannot be applied to very small scales), nor does it account for relativistic effects (which are most relevant when dealing with strong gravitational fields or velocities close to the speed of light). In Lagrangian mechanics, we define a quantity known as the Lagrangian of our physical system:

L=T−V.\begin{aligned} L &= T - V. \end{aligned}

Where TT is kinetic energy and VV is potential energy of our entire physical system. It is important to note that only conservative forces contribute to VV. Lagrangian mechanics can account for non-conservative (i.e. dissipative) forces, too, but we will get to how one handles them later.

Euler-Lagrange equations

When there are no non-conservative forces, the equations of motion can be derived by first determining our system's Lagrangian and then applying a set of partial differential equations known as the Euler-Lagrange equations to this Lagrangian. The Euler-Lagrange equations are:

ddt∂L∂q˙i−∂L∂qi=0,i∈{1,2,3,...,n}.\begin{aligned} \hspace{4cm}\dfrac{d}{dt} \dfrac{\partial L}{\partial \dot{q}_i} - \dfrac{\partial L}{\partial q_i} &= 0, \hspace{2cm} i\in \{1,2,3,...,n\}. \end{aligned}

qiq_i are the nn degrees of freedom of our problem and q˙i\dot{q}_i are their time derivatives. The ddt\dfrac{d}{dt} is not a partial derivative and this is purposeful, as when we differentiate ∂L∂q˙i\dfrac{\partial L}{\partial \dot{q}_i} with respect to tt, we treat qiq_i and q˙i\dot{q}_i as functions of tt and wherever they appear in ∂L∂q˙i\dfrac{\partial L}{\partial \dot{q}_i} we differentiate them against tt.

Next, I should explain what "degrees of freedom" are. They are essentially our variables of interest. For simpler problems, the degrees of freedom in our problem are often the spatial dimensions of our problem. For instance, if we were to study an object in free fall and we were to try to simplify our problem as much as possible and not consider any movement in the horizontal directions then nn could be 1 and q1q_1 would just be the height of the object above ground level.

Likewise, when we study the simple pendulum — which is a problem in which we have an idealized rigid pendulum whose rod has zero mass, zero friction and for which there is absolutely no air resistance — typically we only consider a single degree of freedom, which is the angle our pendulum's rod makes with either the negative yy axis or the positive xx axis, depending on the preferences of whoever is setting up the problem.

Derivation of Equations (3)

The derivation of Equations (3) requires knowledge of a field of mathematics known as the calculus of variations as well as a physics principle known as the stationary action principle. If you are interested in learning more, I'd suggest you check out Veritasium's video on this topic (https://www.youtube.com/watch?v=Q10_srZ-pbs). In short, I will say that there's a quantity known as the action, which is denoted as SS, that is defined as:

S=∫t0tfL(qi,q˙i,t)dt.\begin{aligned} S &= \int_{t_0}^{t_f} L(q_i, \dot{q}_i, t) dt. \end{aligned}

One interesting property of the action is that nature consistently sets it to its stationary point, and this is regardless of context. Regardless of whether we're examining the motion of planets with Newton's third law, or studying the behaviour of black holes with general relativity, or checking out the behaviour of subatomic particles, there is always an action that is at its stationary point. Traditionally, this stationary point is typically thought of as a minimum (hence why this is also known as the principle of least action), but strictly speaking it is not always a minimum. When you use the calculus of variations to find the minimum of Equation (4), Equations (3) pops out.

Non-conservative forces

I guess next I should explain how we account for non-conservative forces. Essentially we replace the 00 in Equations (3) with:

Qi=∑j=1mFj⋅∂rj∂qi=∑j=1mFj⋅∂r˙j∂q˙i.\begin{aligned} Q_i &= \sum_{j=1}^m \textbf{F}_j \cdot \dfrac{\partial \textbf{r}_j}{\partial q_i} \\ &= \sum_{j=1}^m \textbf{F}_j \cdot \dfrac{\partial \dot{\textbf{r}}_j}{\partial \dot{q}_i}. \end{aligned}

Where Fj\textbf{F}_j represents the vector of the jjth non-conservative force we wish to account for in our equations of motion. As you can see by the summation bounds, we have mm non-conservative forces we wish to account for. rj\textbf{r}_j is the position vector for force jj. r˙j\dot{\textbf{r}}_j is the time derivative of the position vector for force jj. Hence the more generalized form of Equations (3) is:

ddt∂L∂q˙i−∂L∂qi=∑j=1mFj⋅∂rj∂qi,i∈{1,2,3,...,n}.\begin{aligned} \hspace{4cm}\dfrac{d}{dt} \dfrac{\partial L}{\partial \dot{q}_i} - \dfrac{\partial L}{\partial q_i} &= \sum_{j=1}^m \textbf{F}_j \cdot \dfrac{\partial \textbf{r}_j}{\partial q_i}, \hspace{2cm} i\in\{1,2,3,...,n\}. \end{aligned}

Single pendulum

Without air resistance

Single pendulum.

So to punctuate how one applies Equations (3) and (6), I thought I would give you a nice, simple example: the single pendulum. To apply Equations (3), we will treat it as a simple pendulum with no friction, a massless rod and air resistance. The pendulum will consist of a rod with a bob at one end and freely rotating around a central pound. We will define this central point as being the origin in Cartesian coordinates. Say the rod is of fixed length ll metres. The pendulum bob will be of mass mm kilograms. As you can see in Figure 1, we have defined θ\theta as the angle between the rod and the positive xx-axis going counter-clockwise. Hence the xx and yy coordinates of the pendulum bobs are:

x=lcos⁡θy=lsin⁡θ.\begin{aligned} x &= l\cos{\theta} \\ y &= l\sin{\theta}. \end{aligned}

Hence:

x˙=−lθ˙sin⁡θy˙=lθ˙cos⁡θ.\begin{aligned} \dot{x} &= -l\dot{\theta}\sin{\theta} \\ \dot{y} &= l\dot{\theta}\cos{\theta}. \end{aligned}

As for velocity squared, it is defined as:

v2=x˙2+y˙2=l2θ˙2sin⁡2θ+l2θ˙2cos⁡2θ=l2θ˙2.\begin{aligned} v^2 &= \dot{x}^2+\dot{y}^2 \\ &= l^2\dot{\theta}^2\sin^2{\theta} + l^2\dot{\theta}^2\cos^2{\theta} \\ &= l^2\dot{\theta}^2. \end{aligned}

Hence v=lθ˙v=l\dot{\theta}. The kinetic energy is:

T=mv22=ml2θ˙22.\begin{aligned} T &= \dfrac{mv^2}{2} \\ &= \dfrac{ml^2\dot{\theta}^2}{2}. \end{aligned}

As for potential energy, given this bob is moving solely under the force of gravity:

V=mgy=mglsin⁡θ.\begin{aligned} V &= mgy \\ &= mgl\sin{\theta}. \end{aligned}

Hence:

L=T−V=ml2θ˙22−mglsin⁡θ.\begin{aligned} L &= T - V \\ &= \dfrac{ml^2\dot{\theta}^2}{2} - mgl\sin{\theta}. \end{aligned}

∂L∂θ˙\dfrac{\partial L}{\partial \dot{\theta}} is hence:

∂L∂θ˙=ml2θ˙.\begin{aligned} \dfrac{\partial L}{\partial \dot{\theta}} &= ml^2 \dot{\theta}. \end{aligned}

And its time derivative is:

ddt∂L∂θ˙=ml2θ¨.\begin{aligned} \dfrac{d}{dt}\dfrac{\partial L}{\partial \dot{\theta}} = ml^2 \ddot{\theta}. \end{aligned}

As for the ∂L∂θ\dfrac{\partial L}{\partial \theta} term it is:

∂L∂θ=−mglcos⁡θ.\begin{aligned} \dfrac{\partial L}{\partial \theta} &= -mgl\cos{\theta}. \end{aligned}

So Equations (3) becomes:

ml2θ¨+mglcos⁡θ=0.\begin{aligned} ml^2 \ddot{\theta} + mgl\cos{\theta} &= 0. \end{aligned}

Dividing by ml2ml^2 and taking the second term to the right-hand side yields:

θ¨=−glcos⁡θ.\begin{aligned} \ddot{\theta} &= -\dfrac{g}{l}\cos{\theta}. \end{aligned}

Technically speaking it is possible to analytically solve Equation (17), but it requires the use of non-standard functions called elliptic integrals. If you would like to check out numerical solutions to this equation, see this page.

With air resistance

For the sake of simplicity, we will only consider the air resistance experienced by the pendulum bob itself, not by the rod. The air resistance force vector for the pendulum bob would be:

FD=−ρCDA∣v∣v2.\begin{aligned} \textbf{F}_D &= -\dfrac{\rho C_D A|v|\textbf{v}}{2}. \end{aligned}

Where v\textbf{v} is the velocity vector of the bob. It is equal to (x˙,y˙)(\dot{x}, \dot{y}). Hence:

FD=−ρCDAl∣θ˙∣2(x˙,y˙)=−ρCDAl∣θ˙∣2(−lθ˙sin⁡θ,lθ˙cos⁡θ)=ρCDAl2∣θ˙∣θ˙2(sin⁡θ,−cos⁡θ).\begin{aligned} \textbf{F}_D &= -\dfrac{\rho C_D Al|\dot{\theta}|}{2}(\dot{x}, \dot{y}) \\ &= -\dfrac{\rho C_D Al|\dot{\theta}|}{2} (-l\dot{\theta}\sin{\theta}, l\dot{\theta}\cos{\theta}) \\ &= \dfrac{\rho C_D Al^2|\dot{\theta}|\dot{\theta}}{2} (\sin{\theta}, -\cos{\theta}). \end{aligned}

To find the generalized force term, we need to find ∂r⃗∂θ\dfrac{\partial \vec{r}}{\partial \theta}:

∂r∂θ=(−lsin⁡θ,lcos⁡θ).\begin{aligned} \dfrac{\partial \textbf{r}}{\partial \theta} &= (-l\sin{\theta}, l\cos{\theta}). \end{aligned}

Hence:

Qθ=ρCDAl2∣θ˙∣θ˙2(sin⁡θ,−cos⁡θ)⋅(−lsin⁡θ,lcos⁡θ)=ρCDAl2∣θ˙∣θ˙2(−lsin⁡2θ−lcos⁡2θ)=−ρCDAl3∣θ˙∣θ˙2.\begin{aligned} Q_{\theta} &= \dfrac{\rho C_D Al^2|\dot{\theta}|\dot{\theta}}{2} (\sin{\theta}, -\cos{\theta}) \cdot (-l\sin{\theta}, l\cos{\theta}) \\ &= \dfrac{\rho C_D Al^2|\dot{\theta}|\dot{\theta}}{2}(-l\sin^2{\theta}-l\cos^2{\theta}) \\ &= -\dfrac{\rho C_D Al^3|\dot{\theta}|\dot{\theta}}{2}. \end{aligned}

Hence Equations (6):

ml2θ¨+mglcos⁡θ=−ρCDAl3∣θ˙∣θ˙2.\begin{aligned} ml^2 \ddot{\theta} + mgl\cos{\theta} &= -\dfrac{\rho C_D Al^3|\dot{\theta}|\dot{\theta}}{2}. \end{aligned}

Dividing by ml2ml^2 yields:

θ¨+glcos⁡θ=−ρCDAl∣θ˙∣θ˙2m.\begin{aligned} \ddot{\theta} + \dfrac{g}{l}\cos{\theta} &= -\dfrac{\rho C_D Al|\dot{\theta}|\dot{\theta}}{2m}. \end{aligned}

Subtracting glcos⁡θ\dfrac{g}{l}\cos{\theta} from both sides yields:

θ¨=−glcos⁡θ−ρCDAl∣θ˙∣θ˙2m.\begin{aligned} \ddot{\theta} &= -\dfrac{g}{l}\cos{\theta} -\dfrac{\rho C_D Al|\dot{\theta}|\dot{\theta}}{2m}. \end{aligned}

This equation cannot be analytically solved, so numerical solutions are necessary. I numerically solve an even more complex version of the single pendulum equation here.

If you would like to see my derivation of the double rigid pendulum equations, it is here.