# Calculus of Variations

## Origins

### Snell's Law

If one treats light as a wave-like phenomena, then Snell's law is readily derivable from geometry.

But, back in 1600's the nature of light (i.e. particle or wave) was anything but settled.

### Principle of Least Time

Q: How does a photon (i.e. not a wave) decide to change directions upon entering and exiting the medium?

A: It has to get to point b in the shortest time.

Since the distance $s$ traveled in time $t$ at a speed $v$ is $$v = \frac{s}{t}$$ and using the fact that the speed of light depends on the local index of refraction: $$v_\textrm{light} = \frac{c}{n(\mathbf{r})}$$ we can express the time to travel an infinitesimal distance $ds$ as : $$dt = \frac{ds}{v} = \frac{ds}{c/n(\mathbf{r})}$$

Integrating this to find the total time it takes: $$t = \int dt = \frac{1}{c}\int n(\mathbf{r}) ds$$

Finding the path ($ds$) that minimizes the total time is essentially the Principle of Least Time, though it would take a few more hundred years to figure out how to really do this math. (and even longer to figure out why it should even be true)

Assuming the index of refraction in our material $n(\mathbf{r})$ only changes with respect to the x position, we could write: $$t = \frac{1}{c}\int ds \; n(x)$$ or, using i.47 $$t = \frac{1}{c} \int n(x) \sqrt{dx^2 + dy^2} = \frac{1}{c} \int n \left(x \right) \sqrt{1 + \left( \frac{dy}{dx} \right)^2} dx$$ which, using the shorthand for $dy/dx = y'$ (in general, a prime will mean take the derivative w.r.t whatever the explicit independent variable is), $$t = \frac{1}{c}\int n(x) \sqrt{1+y'^2} dx$$

Lastly, the index of refraction should be limited to just x dependent changes: $n(x,y)$ is more general. $$t = \frac{1}{c}\int n(x,y) \sqrt{1+y'^2} dx = \int F(x,y(x),y'(x))dx$$ Now, the function $F$ can be seen to depend on $x$, $y(x)$, and $y'(x)$. The techniques that follow will seek to find the path $y(x)$ that minimizes this integral.

Getting even more general, if: $$I = \int F(x,y(x),y'(x))dx$$ Can we find paths $y(x)$ that also maximize $I$? Or, even find what we'll call a stationary path, where the value of $I$ is nearly independent of small changes in the path?

The mins & maxes of a function are just the zero-crossings of the first derivative.

#### Functions of Two Variables

Find the max of this inverted paraboloid

$$f(x,y) = -a \left( (x-x_0)^2 + (y-y_0)^2 \right)$$

a = 1;
x0 = 2; y0 = 3;
paraboloid [x_, y_] := -a ((x - x0)^2 + (y - y0)^2)
Maximize[paraboloid[x, y], {x, y}]
Show[ContourPlot[paraboloid[x, y], {x, -5, 10}, {y, -5, 10},
Frame -> True, AxesOrigin -> {0, 0, 0},
ColorFunction -> "DarkRainbow", GridLines -> Automatic],
Graphics[{White, PointSize[Large], Point[{x, y} /. Last[%]]}]]

The path length for all the different paths from $a$ to $b$ can be considered a function.

The function is now what we want to find stationary points for.

## Euler-Lagrange Equation

$$\frac{\partial F}{\partial y(x)}-\frac{d}{dx}\left(\frac{\partial F}{\partial y'(x)}\right)=0 \label{eq:eulerlagrange}$$

Show that the shortest distance between 2 points is a straight line

Find the shape of a ramp that will bring a sliding mass to a lower point the fastest.