Week 11 - Notes: The Euler-Lagrange Equation#
As we will use it, the Calculus of Variations foucses on finding the conditions of extrema for quantities that can be expressed as an integral. This might be a very abstract concept, so we will start with a simple example.
This approach might seem a bit alien at first, but it turns out to be an interesting way to develop an equivalent formulation of mechanics. Moreover, the Calculus of Variations is a powerful tool in many fields, and forms the basis for Lagrangian mechanics.
To do this, we will derive (in 1D) the Euler-Lagrange equation. This equation gives us a way to find the function that makes the integral of a given functional stationary (i.e., a local maximum or minimum).
Canonical Conceptualization - Finding the Shortest Path in a Plane#
Using the Calculus of Variations, we can show that the shortest path between two points in a plane is a straight line. This is a classic example, but it illustrates the concept well. Consider a general path in two-dimensional space that connects two points, say
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-v0_8-colorblind')
x1, x2 = 1, 5
xvals = np.linspace(x1, x2, 100)
ygeneric = np.sin((xvals - x1) / (x2 - x1) * np.pi/3) * (3) / 10 + (0 + 3) / 2 + 2*xvals**2
y1, y2 = ygeneric[0], ygeneric[-1]
fig, ax = plt.subplots()
ax.plot(xvals, ygeneric, label=r'Generic Path, $y(x)$', color='C0')
ax.plot([x1, x2], [y1, y2], label='Shortest Path', color='C1', linestyle='--')
ax.plot(x1, y1, 'C2o') # Point 1
ax.plot(x2, y2, 'C2o') # Point 2
# blank ticks
ax.set_xticks([]) # Remove x ticks
ax.set_yticks([]) # Remove y ticks
# Set labels and title
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Shortest Path Between Two Points in a Plane')
# Add a legend to the plot
ax.legend()
# Show the plot
plt.grid(True) # Add grid for better readability
plt.show() # Display the plot

The blue solid line is the ‘generic path’ that connects the two points
Setup of the Problem#
Let’s take a generic segment of the path
The length of the path from
We want to minimize this length,
Let’s write the expression for
where
The function
Note that
Deriving the Euler-Lagrange Equation#
The mathematical derivation involves extremizing the integral using a perturbation approach. The generic integral we are trying to minimize is for a function of the form:
where
We assume
Because we are looking for a minimum, we notice that when
We start that analysis by differentiating the integral with respect to
We can now differentiate.
Let’s take each term in turn. The first term is:
Let’s focus on the second part of that term:
Let’s look at the second term:
Again, let’s focus on the second part of that term:
Lastly, the third term:
This term is a bit different. The
Putting it all together, we have:
Our expression is still in terms of
Why? Because
We are seeking
Integration by Parts#
Now to deal with the integral here, we can use integration by parts:
The first term
Here, we note
Notice that the surface term evaluates to zero because we have fixed the endpoints of the path, so
Important
The last statement is true for any arbitrary function
This is the Euler-Lagrange equation for a 1D problem.
Back to the Shortest Path Example#
Now let’s apply the Euler-Lagrange equation to our original problem of finding the shortest path between two points in a plane. We have:
Here, we can identify our function
Let’s apply the Euler-Lagrange equation to this function.
We take the derivatives:
since
Let’s put all this together:
This means that,
This implies that:
Or rearranging gives us:
So that,
Integrating gives us:
where
Example: Snell’s Law#
Let’s assume you are walking on the beach and need to get to a location in the water quickly. Where do you enter the water to minimize the time it takes to reach the location in the water? This is a classic problem in physics and can be solved using the Calculus of Variations.
Consider the picture below where you can move at a speed
Notice the angle that we approach the shoreline at,
The total time to travel from
where
This gives us:
We want to minimize this time,
where the last step is just substituting in the expressions for
This gives us:
Important
This is Snell’s Law! It tells us that the ratio of the sine of the angles to the velocities is constant. This is a classic result in optics, but it also applies to this problem of finding the shortest path in a plane.
Example: Brachistochrone Problem#
The Brachistochrone problem is a classic problem in the Calculus of Variations. It asks the question: “What is the shape of the curve that a bead will follow under the influence of gravity to reach the bottom in the shortest time?” Here’s a great video from Steven Strogatz that explains the problem and its solution.
Source: https://www.youtube.com/watch?v=Cld0p3a43fU
The setup is below, there’s two points separated by a distance vertically and horizontally. What shape should we make a track so that a bead will roll down it in the shortest time?
The time it takes for the bead to roll down the curve is given by:
where
Velocity of the Bead#
What about
If the bead starts from rest, then
where
Let’s move the origin to the top of the track and measure
We can now write the integral again,
We notice that we can factor out a
where
We can identify our function
Because
Or that this partial derivative must be a constant:
where
Knowing the solution ahead of time, we choose the constant
Some more algebra gives us:
where
This integral will give us the shape of the curve
Let
Note that
where
With initial conditions
This is the “cycloid” curve that the bead will follow to minimize the time it takes to roll down the track. We can plot this curve to visualize it.
What is so interesting about this curve is that it is isochronous, meaning that all beads released from rest at any point on the curve will reach the bottom at the same time, regardless of where they start.
Show code cell source
## Plot a cycloid path for comparison
## $$x(\theta) = a\left(\theta - \sin(\theta)\right)$$
## $$y(\theta) = a(1 - \cos(\theta)).$$
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-v0_8-colorblind')
# Cycloid parameters
a = 1 # Radius of the rolling circle
theta = np.linspace(0, 3/2 * np.pi, 1000) # Parameter for the cycloid
# Cycloid equations
x_cycloid = a * (theta - np.sin(theta))
y_cycloid = -a * (1 - np.cos(theta))
# Create the plot
fig, ax = plt.subplots(figsize=(10, 4)) # Create a new figure and axis
ax.plot(x_cycloid, y_cycloid, color='C0')
ax.plot(0, 0, 'C1o', label='Start') # Starting point of the cycloid
ax.plot(x_cycloid[-1], y_cycloid[-1], 'C2o', label='End') # Ending point of the cycloid
# Set labels and title
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Cycloid Path')
ax.legend() # Add a legend to the plot
# Show the plot
plt.grid(True) # Add grid for better readability
plt.show() # Display the plot
