## A brief introduction to Lagrangian mechanics

Disclaimer: what follows assumes familiarity with both Newtonian mechanics, and with calculus (we are going to use the chain rule a lot). This is also no substitute for a proper textbook, as we will skip over a lot of details.

The first question we need to answer before we even start thinking about Lagrangian mechanics is: "who cares?" After all, using Newton's laws of motion you can solve every mechanical system, so why bother?
The point is that you can, but it is not always easy (nor convenient) to do so. In particular Newton's laws are a bit of a headache every time you have constraints. To see it let's consider a simple example: point mass, constrained to slide without friction on a parabolic guide, under the effect of a uniform gravitational field. There are 2 forces acting on the mass:
1. The gravitational force.
2. The reaction of the constraint.
The force due to the constraint has two parts:
2.1 The reaction to the gravitational force.
2.2 The (centripetal) reaction of the constraint to the motion of the mass, keeping the mass always on the parabolic guide. $F_1 = - m g \hat{z}~;~F_{2.1}= (F_1\cdot\hat{n})\hat{n}~;~F_{2.2}=\frac{m v^2 }{R}\hat{n}$ Where $$m$$ is the mass, $$v$$ its velocity, $$g$$ the gravity acceleration, $$\hat{n}$$ the normal to the parabolic guide (i.e. the constraint), and $$R$$ the radius of curvature of the parabolic guide.
(If you are not familiar with the lastforce, it is because you only ever saw examples where the guide is straight, so $$R$$ is infinite.)
Is this solvable? Of course it is! But having to keep track of both the normal vector and the radius of curvature is annoying, and makes the calculations way more complicated than necessary.
Can we do any better?

As a first (not yet very useful) step, we notice that in Cartesian coordinates, the $$i$$th component of the force can be rewritten in terms of the derivative with respect of time and the velocity in the $$i$$th direction of the kinetic energy $$T$$: $F_i = m \ddot{x}_i=\frac{d}{dt} m \dot{x}_i=\frac{d}{dt} \frac{\partial}{\partial \dot{x}_i} \left( \frac{m}{2} \dot{x}_i^2 \right)=\frac{d}{dt} \frac{\partial T}{\partial \dot{x}_i} .$ The actually smart trick we are going to use here is to realize that we don't really care about the motion along all the Cartesian coordinates, we only care about the motion along a smaller set of coordinates (as some degrees of freedom are taken away by the constraints). In our case for instance we only care about the motion of the mass along the parabolic guide. We call these new coordinates $$q_j$$, and now we want to write an equivalent of the formula connecting the forces and the kinetic energies, but this time we want it to depend on the new coordinates $$q_j$$: $\frac{d}{dt} \frac{\partial T}{\partial \dot{q}_j} = \frac{d}{dt} \frac{\partial}{\partial \dot{q}_j} \sum_i \frac{m_i}{2} \dot{x}_i^2 = \frac{d}{dt} \sum_i m_i \dot{x}_i \frac{\partial \dot{x}_i}{\partial \dot{q}_j} .$ If $$x_i$$ does not depend $$\dot{q}_j$$, we can use the chain rule again to obtain: $\frac{\partial \dot{x}_i}{\partial \dot{q}_j}=\frac{\partial}{\partial \dot{q}_j} \sum_k \frac{\partial x_i}{\partial q_k} \dot{q}_k = \sum_k \frac{\partial x_i}{\partial q_k}\frac{\partial \dot{q}_k}{\partial \dot{q}_j}=\frac{\partial x_i}{\partial q_j} ,$ and simplify the equation above, leaving a term that now depends only on the force component along $$q_j$$. I.e. we now have an equation of motion that doesn't care at all about the constrain forces. Not bad for a bit of symbol manipulation trickery! $\frac{d}{dt} \frac{\partial T}{\partial \dot{q}_j}= \frac{d}{dt} \sum_i m_i \dot{x}_i \frac{\partial \dot{x}_i}{\partial \dot{q}_j}= \frac{d}{dt} \sum_i m_i \dot{x}_i \frac{\partial x_i}{\partial q_j} =$ $= \sum_i m_i \ddot{x}_i \frac{\partial x_i}{\partial q_j} +\sum_i m_i \dot{x}_i \frac{\partial \dot{x}_i}{\partial q_j} = \sum_i F_i \frac{\partial x_i}{\partial q_j}+ \frac{\partial T}{\partial q_j} .$
It is common to rearrange a bit this result, and it goes under the name of "Lagrange's equation of the first kind": $\frac{d}{dt} \frac{\partial T}{\partial \dot{q}_j} - \frac{\partial T}{\partial q_j} =\sum_i F_i \frac{\partial x_i}{\partial q_j} .$ This already solves a lot of our problems with constraints, but it still require us to keep track of all the forces. Can we do better?

We can if the forces are conservative, and thus can be written in terms of a (scalar) potential $$V$$. Now we don't even need to keep track of the (vector) forces any more. $F_i = - \frac{\partial V}{\partial x_i} \Rightarrow \sum_i F_i \frac{\partial x_i}{\partial q_j} = -\sum_i \frac{\partial V}{\partial x_i} \frac{\partial x_i}{\partial q_j} = -\frac{\partial V}{\partial q_j} .$ If the potential $$V$$ does not depend on the velocities (i.e. it does not depend on $$\dot{q}_j$$) we can define the Lagrangian $$L=T-V$$ and write down our equations of motion in a very compact and elegant form, the Euler-Lagrange equation (of second kind): $\frac{d}{dt} \frac{\partial T}{\partial \dot{q}_j} - \frac{\partial T}{\partial q_j} = -\frac{\partial V}{\partial q_j} \Rightarrow \frac{d}{dt} \frac{\partial (T-V)}{\partial \dot{q}_j} - \frac{\partial (T-V)}{\partial q_j} = 0$ $\Rightarrow \frac{d}{dt} \frac{\partial L}{\partial \dot{q}_j} - \frac{\partial L}{\partial q_j} =0 .$
So, at the price of a few assumptions, and some symbol manipulation, we have now a formulation of Newton's laws that makes much easier to deal with constraints. Obviously the two approaches describe exactly the same Physics, but Lagrangians are often much simpler to deal with.

Now is the time to talk about all the dirt we swept under the rug. In particular we made a hidden assumption on the nature of the constraints. Everything we have done work if the constraints are "holonomic". We can informally say that a holonomic constraint is one where the state of the system depends only on the values of its coordinate (plus time), and not on the path it took to arrive there. So our parabolic waveguide was holonomic, but a ball rolling on a plane is not.
There are also cases where things still works even though some of the assumptions are violated. E.g. the magnetic force depend on velocity, but all the problematic parts cancel out and we can write a Lagrangian for the Lorentz force.