Introduction to Lagrangian Mechanics

I’ll be honest. There is a lot of stuff to talk about when we are talking about the Lagrangian. It’s not super simple — but it is super powerful.
Newtonian Mechanics
Before jumping into Lagrangian mechanics, let’s think about Newtonian mechanics. At the most basic level, this uses the momentum principle and the work-energy principle:

Newtonian mechanics works best if you can calculate the forces directly. Some examples of calculated forces would be:
- The gravitational force
- Air resistance
- The force from a spring
- Electromagnetic forces
For example, consider a mass hanging vertically on a spring.

Since you can get an expression for both the spring force and the gravitational force, you can use the momentum principle to find the acceleration and find an equation of motion (yes, you need to solve a differential equation).
But what about something like this mass swinging on a string (pendulum).

What’s the problem here? In this case you again have the gravitational force — but there is also the force from the string. This string force (tension) changes in both magnitude AND direction. There is no simple equation for tension here because it’s a constraint force. The string applies whatever force it needs in order to keep the mass at the same distance from the pivot point.
There are some tricks to deal with these constraint forces — for example, you could switch to polar coordinates where the tension doesn’t even matter. But that means you need the acceleration in polar coordinates. It’s not as simple as it should be. Here is that solution (if you are interested):
Oh, let me just put the solution for this pendulum here.

Don’t worry, I’ll explain that “double dot” notation shortly. I just want to show you this equation so that we can get it using Lagrangian mechanics later.
But what about a pendulum with two masses? Like this (a double pendulum):

Now you have two forces of constraint. This is pretty much impossible to solve with Newtonian mechanics. So, Newtonian mechanics works well in some cases — but it’s not the best when dealing with forces of constraint.
Principle of Least Action and the Lagrangian
OK, this part is a little weird — but just hang with me. I’ll start with the definition of the Lagrangian. It’s the difference between the kinetic energy and potential energy for some system. In classical mechanics, we like to be cool and use T to represent kinetic energy. Here is the Lagrangian.

In one dimension, this Lagrangian will be a function of position, velocity and time. Here is another fun twist that might be new to you. Since velocity is the time-derivative of the position, we write velocity using “dot notation”. If you put one dot over a variable, that represents the first derivative (with respect to time). Two dots means the second derivative. Like this:

Now for another definition — the Action. The action is a path integral of the Lagrangian over time. I know, that doesn’t seem to make any sense. Trust me, I get that. If the action is represented by the symbol S then, it can be calculated as:

Who cares about action? Well, it just so happens that the world-path (position and time) of the actual object is such that the action is minimized. This is the principle of least action.
How about an example? Let’s say I take a ball and toss it straight up in the air (no air resistance).

In this case, the kinetic energy and potential energy would be (assuming y = 0 at the ground):

Now, let’s assume I don’t actually know the equation of motion for this ball in the air — but for simplicity, I will assume it has a constant acceleration. Since I don’t know the acceleration, I’m going to just change it and get a whole bunch of different trajectories. Here are the different position vs. time plots that I could get.

But which acceleration gives the “least action”? Here is the action (S) for different values of acceleration.

And there you have it. The “world path” with an acceleration of 9.8 m/s² gives the least action. Yes, you could try some other stuff — like a ball that moves up with a constant velocity and then down with a constant velocity. But trust me, this actually is the motion of least action.
Euler-Lagrange Equation
OK, we have a problem. The previous example was super simple in that I just varied one parameter (the acceleration) to find the least action. But how do you find a function that minimizes a path integral? Remember that the action (S) is a path integral over time. You can’t just use the whole max-min calculus method since you are changing a function.
This is where the Euler-Lagrange equation becomes useful. Suppose you have some path integral in this following form.

The function (f) that minimizes this integral must satisfy the Euler-Lagrange equation:

Then you could use this to do stuff like finding the path of the shortest distance between two points:
Or perhaps you would like to find the path through which an object can move (under the gravitational force) that gives the shortest time between two points. This is famous (and surprisingly tricky) Brachistochrone problem.
Motion of a Ball with Lagrangian Mechanics
I think we are ready for an example. Since we want to find a function that minimizes the action integral, we can use the Euler-Lagrange equation to get the following generic expression.

In this form, q is some generalized variable. There is an “i” subscript since you could have multiple dimensions. You are going to see that these variables are the key to the ultimate power of Lagrangian mechanics. In general, we are going to use the following recipe for solving problems.
- Pick coordinates (more on this later).
- Find T, U and get L.
- Use the Euler-Lagrange equation.
- Hopefully get an expression that gives a differential relationship that maybe can be solved.
Enough talk. Let’s do. Here is the situation. A ball (mass m) is tossed straight up with an initial velocity v0. Using y as my variable (that just makes the most sense), I get the following Lagrangian.

Let’s break this Euler-Lagrange equation into parts. I’ll start with the partial with respect to y.

Remember, when you take a partial derivative you assume that only the variable y is changing. OK, you knew that. Well, here is the partial of L with respect to y-dot.

Now I need to take the actual time derivative (not a partial) of this to get:

Putting these two together in the Euler-Lagrange equation, I get:

This is a very simple differential equation that says that the acceleration in the y-direction is equal to -g. Yes, we already knew that — but it’s best to start off with simple stuff.
Of course, we aren’t technically finished. You would still have to solve this differential equation — but that’s not too bad. You can just integrate twice and apply the initial conditions.
Lagrangian Pendulum
Let’s go back to this pendulum problem. It’s a mass hanging from a string. Here is a diagram.

So, the first thing to consider is the degrees of freedom. How many variables would you need to completely describe the position of this system? The answer is ONE. There is only one variable you need in this case and that variable is θ.
The next step is to write down the kinetic and potential energy. But how do you get the kinetic energy in terms of θ? Yes, you might already know how to write this, but let’s go through the full procedure so that you can use this with more complicated (and not so obvious) systems.
But you know what is simple? Writing the kinetic energy (and potential) in terms of Cartesian coordinates. If I use the variables x and y, then I get:

With a right triangle, I get the following relationship between x,y and θ.

It’s pretty obvious to how to use this for the potential energy term. Just substitute for y. Oh, notice that the mass has a negative y-value if I assume the pivot point is at y = 0. But it’s still easy for the potential. However, for the kinetic energy, I need to first take the time-derivatives of x and y. This is what I get.

Be careful. These are actual derivatives. That means that for x, I have to take the derivative of sine AND the derivative of θ. Don’t forget about your chain rule!
Now I can square these derivatives and add them together to get the kinetic energy in terms of θ and θ-dot.

Notice that I can factor out some stuff so that I get sin²θ + cos²θ which is just equal to 1. This gives a Lagrangian of:

Next I get to use the Euler-Lagrange equation. Here are the two terms:

Putting these together, I get the following:

Boom. That’s the same differential equation we get from the Newtonian method of solving the pendulum problem. There are a couple of ways to solve this differential equation — but I did that in the Newtonian video above.
So, which method is better? For this problem, you could make the argument that both are better in a certain way. But how about this? Which method could you use with the double pendulum? The answer is Lagrangian mechanics.
I should probably write a classical mechanics textbook. Maybe I will just keep posting stuff here.