Solution (source code)

= Solution

A $C^1$ <embedded submanifold> $M\subseteq\mathbb R^n$ of dimension $n-1$ is locally the graph of a $C^1$ function of $n-1$ coordinates after a change of coordinates. Equivalently, near each point $x_0\in M$ it is a regular level set $\{x:h(x)=0\}$ of a $C^1$ scalar function with $\nabla h(x_0)\neq0$.

The <Lagrange multiplier> theorem says that if a $C^1$ function $F$ has a constrained local extremum at $x_0$ on such a level set, then
$$
\boxed{\nabla F(x_0)=\lambda\nabla h(x_0)}
$$
for some real $\lambda$. Indeed the derivative of $F$ must vanish on the <tangent space> $T_{x_0}M=\ker Dh(x_0)$, whose normal space is the line spanned by $\nabla h(x_0)$. The nonzero-gradient condition is essential.