stylistic:style_transfer
Optics

Fermat's principle states that light takes a path that (locally) minimizes the optical length between its endpoints. If the x {\displaystyle x} -coordinate is chosen as the parameter along the path, and y = f (x) {\displaystyle y=f(x)} along the path, then the optical length is given by

where the refractive index n (x, y) {\displaystyle n(x,y)} depends upon the material.If we try f (x) = f 0 (x) + ε f 1 (x) {\displaystyle f(x)=f_{0}(x)+\varepsilon f_{1}(x)} then the first variation of A {\displaystyle A} (the derivative of A {\displaystyle A} with respect to ε) is

After integration by parts of the first term within brackets, we obtain the Euler–Lagrange equation

The light rays may be determined by integrating this equation. This formalism is used in the context of Lagrangian optics and Hamiltonian optics.