Solution (source code)

= Solution

For fixed endpoint values, the first variation of the <functional>
$$
I[z]=\int_a^b f(z,z';x)\,dx
$$
vanishes exactly when the <Euler-Lagrange equation>
$$
\boxed{\frac{d}{dx}\frac{\partial f}{\partial z'}
-\frac{\partial f}{\partial z}=0}
$$
holds. If $f$ has no explicit $x$ dependence, differentiation along an extremal gives the <Beltrami identity>
$$
\boxed{f-z'\frac{\partial f}{\partial z'}=\text{constant}}.
$$
For a further constraint $J[z]=J_0$, introduce a constant <Lagrange multiplier> $\lambda$ and apply the Euler-Lagrange equation to $I+\lambda J$; $\lambda$ is then chosen so that the constraint holds.