This post was translated from Korean into English by AI.
I studied Lagrangian mechanics briefly a long time ago. I think it was probably when I was a high school senior, back when everything except studying for school exams was interesting, and I needed to do some complicated physics calculations for something. I do not remember exactly what I was trying to do, though. I think it may have been to simulate a double pendulum.
Anyway, I have occasion to use it again, so I would like to organize my notes on it this time.

Calculus of Variations
Lagrangian mechanics uses a branch of mathematics called the calculus of variations, which extends ordinary calculus.
The calculus of variations deals with things called functionals. A functional is a function whose domain is a set of functions. Its codomain could, of course, also be any number of sets, but this post will cover only the case where the codomain is the real numbers. In other words, if the set of functions covered in this post is denoted by and the set of real numbers by , a functional here means a function . The following is an example of a simple functional.
The functional in the expression above takes some function as its argument (assuming that is a real-valued function) and returns a real number.
In calculus, given a function, we examine the relationship between an infinitesimal change in its argument and the corresponding infinitesimal change in the function's value. Likewise, the calculus of variations deals with the relationship between an infinitesimal change in its argument—a function—and the infinitesimal change (variation) in the functional. Cases that maximize or minimize a functional are particularly important. Such maximum or minimum values are called stationary values, and a function that makes a functional attain a maximum or minimum is called a stationary function or stationary point. For example, the functional above has the stationary value only when , and is its stationary point (or stationary function).
Euler–Lagrange Equation
There are, of course, countless important principles in the calculus of variations that I do not know, but the Lagrangian mechanics we will discuss is derived mainly from an important equation called the Euler–Lagrange equation.
The Euler–Lagrange equation is an equation used to find a stationary point of a functional of the following form for some function .
Here, is an arbitrary three-variable function whose partial derivatives are all continuous. (It is an ordinary function, not a functional.) And, of course, must be differentiable. For example, if we assume that , the expression above can be written as follows.
(In this case, it is not difficult to see that .)
If some stationary point of a functional of this form is , then satisfies the following equation.
This equation is called the Euler–Lagrange equation.
Fundamental Lemma of the Calculus of Variations
To prove the Euler–Lagrange equation, we first need to understand the fundamental lemma of the calculus of variations. The fundamental lemma of the calculus of variations states that if
-
is a continuous function, and
-
the following holds for every compactly supported smooth function ,
-
then .
In a way, this seems quite obvious. If integrating multiplied by anything always gives zero, then is zero.
Proof
I actually major in computer science, not mathematics, so I do not know much about the condition “compactly supported smooth.” From what I have found, however, it seems fine to regard this as meaning infinitely differentiable at every real number (continuous at every real number, with no divergent values).
Let us prove this by contradiction. That is, suppose there exists some remarkable such that for every , but for which at least one exists such that .
First, let us consider the case where .
Since is continuous, by the definition of continuity there exists some interval containing for which for every . Of course, .
Now consider the following function.
This is a compactly supported smooth function. Then,
When we chose the interval , we chose it so that , and as well. Therefore, , and consequently . But this contradicts our initial assumption that . The assumption is therefore false, and no such exists.
The case where can be proved in the same way.
An Easier Proof (?)
Thinking about it, I believe that a considerable number of the functions dealt with in physics (especially mechanics) are compactly supported and smooth. So let us add one more constraint: suppose that is compactly supported and smooth.
In that case, setting gives , so , and we can intuitively see that equality holds only when .
Proof of the Euler–Lagrange Equation
Before looking at a functional, let us first examine an ordinary function. In calculus, saying that a function of a vector has a local minimum (or maximum) at meant that, for any , if
then . (We could in fact just write , but I deliberately introduced a new function to put this into exactly the same form as the functional below.) In other words, we regarded a point as an extremum if an infinitesimal change in any direction around that point produced zero change.
We can think about a functional's stationary value in a similar way.
Let us look once again at the functional described above. (From this point on, several variables appear, including and . The first two are real numbers, while the latter two are functions. To avoid confusion as much as possible, when something is a function I have tried to indicate both that it is a function and what its argument is, as in .)
If is a stationary point of the functional —that is, if it minimizes or maximizes —then for any differentiable function such that , it will satisfy the following (as in the case of a vector function).
This means that even if we change the function infinitesimally by adding the very small function , the value of will barely change.
Now let us substitute the original expression back into and simplify it.
The integrand looks complicated, but that is only because it contains so many symbols; it is nothing more than the total derivative of a multivariable function. Let us expand it.
The expression has become even more complicated. There is a trick hidden here, however: when differentiating as in , the result is zero if the variable of the function being differentiated and the variable with respect to which it is differentiated are different. For example, this applies to in the first term , so it becomes zero. Eliminating all the terms that become zero in this way gives the following relatively neat expression. (From this point on, there is little risk of confusing the arguments, so for readability I will omit the function argument . However, because is an ordinary function rather than a functional, it can take only scalars as arguments. Please note, therefore, that we are passing function values as arguments, not the functions themselves.)
Let us put this back inside the integral sign.
Now let us return to our initial discussion.
If is a stationary point of the functional —that is, if it minimizes or maximizes —then for any differentiable function such that , it will satisfy the following.
So let us set . We then obtain the following expression.
To eliminate here, let us integrate the second term by parts. The formula for integration by parts is as follows.
Let us integrate by parts with and .
But when we first defined , we said
...if it maximizes , then for any differentiable function such that ...
Therefore, the second term becomes zero, and the expression simplifies as follows.
It is now time to use the fundamental lemma of the calculus of variations that we proved earlier. is not a special function; it is an arbitrary differentiable function. According to the fundamental lemma of the calculus of variations, if the integral of a function multiplied by an arbitrary function is always zero, that function itself must be zero.
From this, we obtain the Euler–Lagrange equation. If you scroll back to the section near the top where the Euler–Lagrange equation was introduced, you will see that it has exactly the same form.