Robot Dynamics: Lagrangian formalism

As we have seen in the first post of this series, deriving the equations of motion, even for a system as simple as a pendulum, can be tedious. Classical mechanics (Newtonian mechanics) requires us to describe all the forces acting upon the system, including constraint forces. For complex systems this quickly becomes time consuming.

However, in the 18th century, Joseph-Louis Lagrange introduced a very interesting reformulation of classical mechanics. The Lagrangian formalism allows us to derive the equations of motion from energies. Thus not dealing with constraints at all provided that we choose our generalized coordinates properly.

Lagrange’s promise

In Lagrangian formalism1, we define a quantity called Lagrangian $L$ as the difference between the kinetic energy $T$ of the system and its potential energy $U$

Given that this quantity is expressed with respect to a set of generalized coordinates $q_i$ and their associated time derivatives $\dot{q_i}$, the Euler-Lagrange equation

allows us to derive the equations of motion of our system. So let’s go through this step by step for the pendulum.

Generalized coordinates

We call generalized coordinates any arbitrary set of parameters that describe the configuration of a system. We don’t have to stick to convential Cartesian coordinates or roll with exotic polar, cylindrical, or spherical coordinates. We want to make our life easy, so we select a minimal set that has enough parameters to fully describe the dynamics of our system. So the number of generalized coordinates will be equal to the number of degrees of freedom.

For our pendulum, it’s clear that we have a single degree of freedom: the angle $\theta$. We’ll chose this as generalized coordinate. The pendulum’s position in Cartesian coordinates can be computed at any time given $\theta$

Kinetic energy

The kinetic energy2 $T$ of any system can be computed as the sum of the kinetic energies of all its moving parts with masses $m_i$ along all axes of motion $x_i$. This mathematically translates to

We can compute the velocity in Cartesian coordinates by deriving the equations seen in last section with respect to time, yielding

Now we plug this back in the formula for kinetic energy, assuming a pendulum of mass $m$ to get the kinetic energy as a function of the angular velocity $\dot{\theta}$

Potential energy

We assumed our pendulum to only be subject to gravity, no dissipative forces apply to it. Thus its potential energy3 $U$ can be defined as a function of its position in the direction of gravity (i.e. $y$ the second Cartesian axis)

Invoking Euler-Lagrange

Now our Lagrangian is expressed as function of our generalized coordinate $\theta$ and its associated time derivative $\dot{\theta}$

We start by computing the left side of the Euler-Lagrange equation for our pendulum

then we compute the right side

And now for the final act, I will merge both sides to reconstitute the Euler-Lagrange equation

we rearrange the terms a bit

…and tadam! That looks familiar. We end up with the same equation of motion previously computed using Newtonian mechanics in the first episode of this series.

But does it scale?

Now this is all fun and simple, but what happens for a more complex system? Say a double or a triple pendulum? Well.. things are simpler in Langrange’s world, but it’s still a long and dull process of deriving expressions by hand. Surely we can make computers do some of the work, if not most of it. Haven’t you heard of automatic differentiation, can’t we use that? Sadly not with the Lagrangian approach, because of the explicit time derivative in the Euler-Lagrange equation. Remember that our generalized coordinate $q$ and their associated time derivatives $\dot{q}$ are both functions of time: $q = q(t)$ and $\dot{q} = \dot{q}(t)$.

In the next episode, we’ll dive into Hamilton’s improvement on Lagrange’s approach and see how we can leverage it to compute the equations of motion of any system with a minimal set of input expressions defining it.


  1. Lagrangian mechanics on Wikipedia

  2. Kinetic energy on Wikipedia 

  3. Potential energy on Wikipedia