Reading and display settings

Appearance

System follows your operating system and keeps following it, even if you change it later. The header's sun, moon and monitor cycle the same three options.

Text size (%) 100%

Default. Scales every text size on the site, equations and tables included.

Reading width 70ch

How much text runs across one line of prose. Narrower is easier to track; wider fits more on screen.

Line spacing 1.6

The leading on body text. Taller leading helps a tired eye stay on the line.

Density

Padding and gaps around controls, cards, and tables — how much breathing room the layout leaves itself.

Motion

System follows your operating system. Reduced removes every transition on this site. Full keeps them on unless your system asks for less.

1

The smoothest path between two poses

The unknown is a function, not a point

Until now the unknown has been a point: a scalar $x$, a vector, a matrix. A trajectory is a different animal. Choosing a path means choosing a value $y(t)$ at every instant, so the unknown is a function and the thing being scored is computed from the whole function. An objective that eats a function and returns a number is called a functional, and the branch of calculus built on it is the calculus of variations.

Our running example is the two-link planar arm. Its end-effector must leave rest at $A$ and arrive at rest at $B$ in exactly $T$ seconds. “From rest” means zero velocity and zero acceleration at both ends. Many curves satisfy that; the smoothest is the one with least rate of change of acceleration, the jerk. Writing $\tau = t/T$ for the normalised time, the winner is the minimum-jerk quintic

$$ \sigma(\tau) \;=\; 10\tau^3 - 15\tau^4 + 6\tau^5, \qquad r(t) \;=\; A + \big(B-A\big)\,\sigma(t/T). $$

It is the unique quintic with $\sigma(0)=0$, $\sigma(1)=1$ and $\sigma'=\sigma''=0$ at both ends, and its jerk cost is the textbook value below — a number you will read off the canvas and check against the analytic one.

$$ J[r] \;=\; \int_0^T \lVert r'''(t)\rVert^2\,dt \;=\; \frac{720\,\lVert B-A\rVert^2}{T^5}. $$

Drag $A$ and $B$, switch the optional via point on to force a bend, and vary the duration. The top canvas is the workspace; the strip below is the scalar progress, speed and acceleration of the two candidates — the straight constant-speed line versus the minimum-jerk quintic. The straight line does no jerking inside, but it starts and stops instantaneously, so all of its roughness hides in two instants; the quintic spreads it out. On the same finite-difference grid its cost is orders of magnitude larger.

Top: the end-effector path — minimum-jerk (solid) and the straight constant-speed line (dashed); drag A, B and the via point. Bottom: progress, speed and acceleration against time for both, computed from the sampled trajectory.

💡 Read the formula in the picture: $T^5$ in the denominator is why a slow, gentle reach is cheap and a fast one is expensive; the quintic is the shape that makes the trade-off exactly.
2

Vary the whole path

A functional, and its derivative with respect to a function

A functional of a scalar path has the form

$$ J[y] \;=\; \int_a^b L\big(t,\,y(t),\,y'(t)\big)\,dt, $$

where $L$ is the Lagrangian — the local price of position and slope at each instant. Distance, time, energy and jerk cost all fit this template. To find the best $y$ we perturb the entire curve by a tiny multiple of another curve, $y_\varepsilon(t) = y(t) + \varepsilon\,\eta(t)$, with $\eta$ vanishing at the endpoints so the ends stay put. Now $J(\varepsilon)$ is an ordinary function of the single number $\varepsilon$, and an optimum must satisfy

$$ \frac{dJ}{d\varepsilon}\Big|_{\varepsilon=0} \;=\; 0 \qquad\text{for every admissible } \eta. $$

That quantity is the first variation of $J$: literally a derivative taken with respect to a function. The demo makes it visible. Start from the minimum-jerk path, bend it by $\alpha$ times a fixed bump $b(t)=64\,t^3(1-t)^3$ that vanishes to third order at both ends, and plot the cost $J(\alpha)$. It is a parabola whose bottom sits exactly at $\alpha = 0$ — the derivative with respect to the shape is zero at the optimum, just as an ordinary derivative is zero at a minimum.

Top: the optimal straight path (solid) and the bulged path (dashed→solid) through the same endpoints. Bottom: $J(\alpha)=\int\lVert r'''\rVert^2\,dt$ against the bulge; the minimum, and the zero derivative, are at $\alpha=0$.

3

The Euler–Lagrange equation

Setting the first variation to zero, once and for all

Do the perturbation calculation symbolically. Substitute $y_\varepsilon$ into the functional and differentiate under the integral:

$$ \frac{dJ}{d\varepsilon}\Big|_{\varepsilon=0} \;=\; \int_a^b \left( \frac{\partial L}{\partial y}\,\eta \;+\; \frac{\partial L}{\partial y'}\,\eta' \right) dt. $$

The second term still contains $\eta'$, which is awkward, so integrate it by parts:

$$ \int_a^b \frac{\partial L}{\partial y'}\,\eta'\,dt \;=\; \left[\frac{\partial L}{\partial y'}\,\eta\right]_a^b \;-\; \int_a^b \frac{d}{dt}\frac{\partial L}{\partial y'}\,\eta\,dt. $$

The boundary term dies because $\eta(a)=\eta(b)=0$. What is left must vanish for every bump $\eta$, and the only way an integral against an arbitrary function can be zero is if the bracket itself is zero at every point. That gives the Euler–Lagrange equation:

$$ \boxed{\; \frac{\partial L}{\partial y} \;-\; \frac{d}{dt}\frac{\partial L}{\partial y'} \;=\; 0 \;} $$

For the shortest path between two points, $L=\sqrt{1+y'^2}$. Since $L$ does not mention $y$, the equation reduces to $\frac{d}{dt}\big(y'/\sqrt{1+y'^2}\big)=0$, i.e. $y'$ is constant: the straight line. Because this $L$ has no explicit $t$, the Beltrami identity $y'\frac{\partial L}{\partial y'}-L=\text{const}$ holds too, and for this $L$ it says the same thing. The demo takes the straight line and perturbs it by $\varepsilon\sin(\pi t)$; the readout shows $dJ/d\varepsilon$ and the residual of the Euler–Lagrange condition. At the minimiser both are $\approx 0$.

Top: the straight minimiser (dashed) and the perturbed path $y=y_0+\varepsilon\sin\pi t$ (solid). Bottom: $J(\varepsilon)=\int_0^1\sqrt{1+y'^2}\,dt$ with the tangent at the current $\varepsilon$; the tangent is horizontal at $\varepsilon=0$.

⚠️ Euler–Lagrange is necessary, not sufficient. A curve with zero first variation is a stationary point of the functional; only convexity (here, the flat, positively-curved Lagrangian) turns it into a true minimum.
4

Optimal control: driving a double integrator

Choosing a function $u(t)$, not just a path

Optimal control is the same idea with a dynamic constraint. The plan is the input $u(t)$ and the state obeys $x''=u$ — a point mass where $u$ is acceleration (a double integrator). Pick the input that carries the mass from $x(0)=0,\,v(0)=0$ to $x(T)=1,\,v(T)=0$ with the least control energy

$$ J[u] \;=\; \int_0^T u(t)^2\,dt, \qquad \text{subject to } x''=u. $$

The state is a cubic in $t$ (because $x''''=0$), the control is its second derivative, and imposing the four endpoint conditions gives the optimum directly. For $T=1$:

$$ x^\star(t) = 3t^2 - 2t^3, \qquad v^\star(t) = 6t - 6t^2, \qquad u^\star(t) = 6 - 12t. $$

The optimal control is linear in time, $J^\star=\int_0^1(6-12t)^2dt=12$. The slider adds a smooth perturbation $p\,g(t)$ to the state with $g=16t^2(1-t)^2$ — value and slope both zero at the ends, so the boundary conditions stay satisfied. The cost is $J(p)=12+204.8\,p^2$: a bowl with its minimum, and a flat optimal control, at $p=0$. This is the linear-quadratic regulator in miniature; the general construction adds a costate and the Pontryagin minimum principle, but the geometry is what the canvas shows.

Top: position $x(t)$ and velocity $v(t)$ for the current perturbation. Bottom: the control $u(t)$ (solid) against the optimal linear control $u^\star=6-12t$ (dashed). At $p=0$ the two coincide and the curve is a straight line.

5

Discrete versus continuous

A computer cannot store a function

The theory lives in continuous time, but a solver must store finitely many numbers. The universal move is to sample the function and replace the integral by a sum. For the arc-length functional that means an inscribed polyline:

$$ J_n \;=\; \sum_{i=0}^{n-1}\sqrt{\Delta t^2 + \Delta y_i^2} \;\;\longrightarrow\;\; \int_a^b\sqrt{1+y'(t)^2}\,dt \;=\; J. $$

This is exactly the Riemann sum of Volume I, Part 8, applied to a functional instead of an area: the polyline is short because it cuts the corners of the curve, and the error falls like $1/n^2$. The waypoint slider coarsens and refines the discretisation; the bottom canvas plots the error on log–log axes, where the slope of the line is the order of convergence. Every trajectory optimiser in practice works this way: discretise, then hand the resulting finite-dimensional problem to the methods of Part 10 or Nonlinear Optimization.

Top: the fixed curve and its $n$-segment inscribed polyline. Bottom: the discretisation error against $n$ on log–log axes; the dashed guide has slope $-2$.

6

Where this shows up

Trajectories are the job description

Robot navigation is trajectory optimisation with obstacles attached: plan a path that is smooth, dynamically feasible and cheap — the same functional as this page, with a constraint added. In state estimation the same functional reappears as a sum of squared errors over a whole trajectory — see Pose Graphs & Loop Closure, where the “path” is the robot's history and the cost is the residual of every odometry and loop-closure measurement. The dynamic constraint $x''=u$ is an ODE, the subject of Differential equations, and the accumulation that turns a rate into a functional is the Fundamental Theorem of The Fundamental Theorem. Minimum-jerk tracking is also why industrial arms move along quintics, and model-predictive control re-solves a short-horizon version of this page at every control tick.

7

The formulae to carry forward

ObjectDefinitionWhere it is used
J[y] = ∫ L(t, y, y') dtA functional: an objective computed from a whole functionThis part; every trajectory cost
y_ε = y + εη, η(a)=η(b)=0A variation: an admissible infinitesimal change of the pathThe derivation of Euler–Lagrange
dJ/dε|₀ = 0 ∀ηFirst variation zero — the stationarity conditionStep 2; the bulge demo
∂L/∂y − d/dt(∂L/∂y') = 0The Euler–Lagrange equationShortest path, mechanics, geodesics
y' ∂L/∂y' − L = constBeltrami identity when L has no explicit tConserved quantities, Step 3
∫₀ᵀ ‖r'''‖² dt = 720 L² / T⁵Minimum-jerk cost for a rest-to-rest quinticRobot arm motion, Step 1
x'' = u, J = ∫ u² dtDouble integrator and quadratic control costLQR, Step 4
8

Further reading

9

Check your understanding

0/4 answered