Calculus of variation

Calculus of variation is about observing how a special kind of function, called a functional, changes. A functional takes an entire function as its input and outputs a single scalar value.

Okay, what does this scalar value give us, you ask? Well, let’s roll up our sleeves and explore this with a scenario.


The Projectile of a Stone

It’s a known fact that the path of a projectile is an arc. We can model this path with a function that describes the projectile’s vertical position over time. Let’s call this path function \(q(t)\).

Let’s understand the quantities at play:

  • Position: \(q(t)\), the height at any given time.
  • Time: \(t\), our independent variable (it “times” things, right? ;) ).
  • Velocity: \(\dot{q}(t)\), the derivative of the path, which gives us the instantaneous velocity.

Now, what if we perturb this path function? This means we consider alternative, “inefficient” paths the stone could have taken, all starting and ending at the same points.


The Action: Quantifying the “Cost” of a Path

Let’s lay out the “cast of characters” for clarity:

  • The Path Function (\(q(t)\)): This is our INPUT. It’s any possible path the stone could take.
  • The Action Functional (\(S[q]\)): This is the “cost machine.” It takes the path function as input.
  • The Action (\(S\)): This is the OUTPUT. It’s the single scalar “cost” value that the Action Functional spits out.

Taking a page from Lagrangian dynamics, we use a cost function called the Lagrangian (\(L\)), which is the difference between kinetic and potential energy at any given instant.

\[L = T - V\]

Where, for our projectile:

  • Kinetic Energy (\(T\)): \(T = \frac{1}{2} m v^2 = \frac{1}{2} m \dot{q}(t)^2\) (here \(v\) is the velocity \(\dot{q}(t)\))
  • Potential Energy (\(V\)): \(V = mgh = m g q(t)\) (here \(h\) is our path function\(q(t)\))

The Action (\(S\)) is the total “cost” for the entire journey, which we get by integrating (summing up) this Lagrangian over the entire time of the flight. The integrand of the Action Functional is the Lagrangian.

\[S = \int_{t_{start}}^{t_{end}} L(q(t), \dot{q}(t)) \,dt = \int_{t_{start}}^{t_{end}} \left( \frac{1}{2} m \dot{q}(t)^2 - mgq(t) \right) \,dt\]

Finding the Most Efficient Path

We are trying to find the one path, \(q_{perfect}(t)\), that makes the Action (\(S\)) a minimum. To do this, we’ll create an “inefficient” test path that is a combination of the perfect path and a small “tweak” (or error). This tweak is controlled by a small number, \(\epsilon\), and an “error shape” function, \(\eta(t)\).

  • Inefficient Path: \(q(t) = q_{perfect}(t) + \epsilon \eta(t)\)
  • Inefficient Velocity: \(\dot{q}(t) = \dot{q}_{perfect}(t) + \epsilon \dot{\eta}(t)\)

This method only works if all paths start and end at the same place. This gives us a “golden rule” for our error function: it must be zero at the start and end.

\[\eta(t_{start}) = 0 \quad \text{and} \quad \eta(t_{end}) = 0\]

Now we have a “cost-vs-tweak” graph, where the total Action \(S\)is a function of our tweak knob\(\epsilon\). We call this \(S(\epsilon)\):

\[S(\epsilon) = \int_{t_{start}}^{t_{end}} L(q_{perfect} + \epsilon \eta, \ \dot{q}_{perfect} + \epsilon \dot{\eta}) \,dt\]

We know the perfect path is the minimum cost, which must be at the “no-tweak” position where \(\epsilon = 0\). From calculus, we know the minimum of a function is at the “flat spot” where its slope (derivative) is zero. This gives us our master equation:

\[\frac{dS}{d\epsilon} \bigg|_{\epsilon=0} = 0\]

Step 1: Differentiating the Action

To solve our master equation, we must find the derivative of the Action, \(\frac{dS}{d\epsilon}\). We can “push” the derivative inside the integral, so our task is to find the derivative of the Lagrangian, \(\frac{dL}{d\epsilon}\), and integrate it over time.

\[\frac{dS}{d\epsilon} = \int_{t_{start}}^{t_{end}} \left[ \frac{d}{d\epsilon} L(q(t), \dot{q}(t)) \right] \,dt\]

We can find the “guts” of this, \(\frac{dL}{d\epsilon}\), in two ways:

1. Manual Substitution (Visual Confirmation)

We can manually substitute the underlying functions first so that \(\epsilon\) is visible, and then apply the derivation.

\[\begin{align*} \\ \frac{dL}{d\epsilon} &= \frac{d}{d\epsilon} \left( 0.5 m (\dot{q}_{perfect}(t) + \epsilon \dot{\eta}(t))^2 - mg(q_{perfect}(t) + \epsilon \eta(t)) \right) \\ &= m (\dot{q}_{perfect}(t) + \epsilon \dot{\eta}(t)) \dot{\eta}(t) - mg\eta(t) \end{align*}\]

This is the derivative at any \(\epsilon\).

At \(\epsilon=0\)

\[m(\dot{q}_{perfect}(t)\dot{\eta}(t) - g\eta(t))\]

2. The “Shortcut” (The Multivariable Chain Rule)

There is a shortcut to find \(\frac{dL}{d\epsilon}\). We can use the partial derivatives of the Lagrangian recipe. Since \(L\) depends on \(q\) and \(\dot{q}\), and both of those depend on \(\epsilon\) via the inefficient path equations:

  • \[q(t) = q_{perfect}(t) + \epsilon \eta(t)\]
  • \[\dot{q}(t) = \dot{q}_{perfect}(t) + \epsilon \dot{\eta}(t)\]
  • \(L(q, \dot{q}) = \frac{1}{2} m \dot{q}^2 - mgq\).

…we must use the chain rule.

The chain rule formula is:

\[\begin{align*} \\ \frac{dL}{d\epsilon} &= \frac{\partial L}{\partial q} \frac{dq}{d\epsilon} + \frac{\partial L}{\partial \dot{q}} \frac{d\dot{q}}{d\epsilon} \\ &= \frac{\partial L}{\partial q} \eta(t) + \frac{\partial L}{\partial \dot{q}} \dot{\eta}(t) \end{align*}\]

First, let’s find the partial derivatives of the Lagrangian recipe:

  • \[\frac{\partial L}{\partial q} = -mg\]
  • \[\frac{\partial L}{\partial \dot{q}} = m\dot{q}(t)\]

Now, we evaluate the expression for \(\frac{dL}{d\epsilon}\) at the specific point \(\epsilon = 0\):

\[\begin{align*} \\ \frac{dL}{d\epsilon}\bigg|_{\epsilon=0} &= m(\dot{q}_{perfect}(t) + 0 \cdot \dot{\eta}(t))\dot{\eta}(t) - mg\eta(t) \\ &= m\dot{q}_{perfect}(t)\dot{\eta}(t) - mg\eta(t) \\ \end{align*}\]

This confirms the shortcut gives the exact same result as the manual method once evaluated at \(\epsilon=0\).


Step 2: Applying the Minimum Condition

We have the instantaneous change in the Lagrangian (which is \(\frac{dL}{d\epsilon}\)). To get the total change in the Action (\(\frac{dS}{d\epsilon}\)), we must integrate this expression over time. Since we have the derivative \(\frac{dS}{d\epsilon}\). We can “push” the derivative inside the integral and apply it directly to the Lagrangian:

\[\frac{dS}{d\epsilon} = \int_{t_{start}}^{t_{end}} \frac{dL}{d\epsilon} \,dt\]

This is the expression for the “slope” at any tweak \(\epsilon\). We only care about the slope at the minimum, where \(\epsilon = 0\). That’s the path assigned by the creator.

\[\frac{dS}{d\epsilon} \bigg|_{\epsilon=0} = \int_{t_{start}}^{t_{end}} \left[ m\dot{q}_{perfect}\dot{\eta} - mg\eta \right] \,dt\]

We set this equal to zero to find the minimum.

\[\int_{t_{start}}^{t_{end}} \left( \dot{q}_{perfect}\dot{\eta} - g\eta \right) \,dt = 0\]

Let’s rearrange this by splitting the integral:

\[\int_{t_{start}}^{t_{end}} g \eta(t) \,dt = \int_{t_{start}}^{t_{end}} \dot{q}_{perfect}(t)\dot{\eta}(t) \,dt\]

This equation is “locked” because it has \(\eta(t)\) and \(\dot{\eta}(t)\). To unlock it, we can use Integration by Parts (IBP) to “swap” the derivative off \(\dot{\eta}(t)\).

Let’s look at the subterm:

\[\int_{t_{start}}^{t_{end}} \dot{q}_{perfect}(t) \dot{\eta}(t) \,dt\]

To apply Integration by Parts, we must match our integral to the standard form $$ \int u \frac{dv}{dt} dt`. Let’s choose our parts:

  • Let \(u = \dot{q}_{perfect}(t)\)
  • Let \(\frac{dv}{dt} = \dot{\eta}(t)\)

Now we find the other necessary components for the IBP formula, \(du/dt\) and \(v\):

  • The derivative of \(u\) is: \(\frac{du}{dt} = \ddot{q}_{perfect}(t)\)
  • The integral of \(dv/dt\) is: \(v = \int \frac{dv}{dt} dt = \int \dot{\eta}(t) \, dt = \eta(t)\)
\[[{\dot{q_{perfect}}}(t) \eta(t)]_{t_{start}}^{t_{end}} - \int_{t_{start}}^{t_{end}} \eta(t) \ {\ddot{q_{perfect}}}(t) dt\]

Now, look at the boundary term resulting from Integration by Parts:

\[[\dot{q}_{perfect}(t)\eta(t)]_{t_{start}}^{t_{end}}\]

Expanding this gives:

\[\dot{q}_{perfect}(t_{end})\eta(t_{end}) - \dot{q}_{perfect}(t_{start})\eta(t_{start})\]

Because of our “golden rule” for the variation, which requires the perturbation to be zero at the endpoints:

\[\eta(t_{start}) = 0 \quad \text{and} \quad \eta(t_{end}) = 0\]

Substituting these zero values into the expanded boundary term shows that the entire term evaluates to zero, Therefore, the boundary term vanishes:

\[\cancel{[\dot{q}_{perfect}(t) \eta(t)]_{t_{start}}^{t_{end}}} = 0\]

This gives us:

\[\int_{t_{start}}^{t_{end}} \dot{q}_{perfect}(t) \dot{\eta}(t) \,dt = - \int_{t_{start}}^{t_{end}} \eta(t) \ddot{q}_{perfect}(t) \,dt\]

Plugging this back into the equation:

\[\int_{t_{start}}^{t_{end}} g \eta(t) \,dt = - \int_{t_{start}}^{t_{end}} \eta(t) \ddot{q}_{perfect}(t) \,dt\]

Rearranging:

\[\int_{t_{start}}^{t_{end}} g \eta(t) \,dt + \int_{t_{start}}^{t_{end}} \eta(t) \ddot{q}_{perfect}(t) \,dt = 0\]

And finally, combine the integrals and factor out our “fake path” \(\eta(t)\):

\[\int_{t_{start}}^{t_{end}} \left( g + \ddot{q}_{perfect}(t) \right) \eta(t) \,dt = 0\]

Step 3: The Final Insight

This is the final, unlocked equation. For this integral to be zero for any and every possible “fake path” function \(\eta(t)\) we can imagine (as long as it’s zero at the endpoints), the Fundamental Lemma of Calculus of Variations tells us that the term inside the parentheses must itself be zero at all times.

The following term must be zero:

\[- \ddot{q}_{perfect}(t) - g = 0\]

Rearranging this, we get our final answer:

\[\ddot{q}_{perfect}(t) = -g\]

Hmm, what is this? This is the equation of motion for a projectile under gravity. It states that the acceleration (\(\ddot{q}\)) must be equal to the constant of gravity (\(-g\)).

Holy smokes! Instead of starting with forces, we started with a more abstract idea—the Principle of Least Action—and arrived at the exact same physical law.

We just derived a result of Newtonian mechanics from a more fundamental principle. Ey voila.


Note on External Forces

This derivation assumes the system is only subject to conservative forces (like gravity) which are included in the potential energy \(V\). If external or non-conservative forces (like friction, air resistance, or applied motor forces) are present, their effect is included by adding a generalized force term (\(\tau_q\)) to the right side of the final equation. This results in the more general Euler-Lagrange equation discussed in Lagrangian Dynamics:

\[\frac{d}{dt} \left( \frac{\partial L}{\partial \dot{q}} \right) - \frac{\partial L}{\partial q} = \tau_q\]