Thus, in two dimensions, $\{g(x,y)=\hbox{const}\}$ is a curve whose tangent vector is perpendicular to $\grad{g}$, and in three dimensions $\{g(x,y,z)=\hbox{const}\}$ is a surface containing many curves each of whose tangent vector is perpendicular to $\grad{g}$.
Thus, since $f$ can only have a local maximum/minimum along a curve if $df=0$ along the curve, $\grad{f}$ must be perpendicular to the curve there.
Now consider the problem of finding the local maxima/minima of $f$ subject to the constraint $g=\hbox{const}$. The idea is to consider the level set (curve or surface) on which $g$ has the given value. The first fact above implies that $\grad{g}$ is everywhere perpendicular to this curve or surface. Furthermore, the second fact above implies that, at a local maximum/minimum, $\grad{f}$ is perpendicular to any curve in the level set. Thus, at a local maximum/minimum, we must have: \begin{equation} \grad{f}\parallel\grad{g} \end{equation} This relationship is shown geometrically in Figure 1, which shows the level curves of $f$, together with a heavy line representing the constraint curve $g=\hbox{const}$. The maximum and minimum values of $f$ clearly take place where the constraint curve is tangent to the level curves.
The method of Lagrange multipliers with one constraint is therefore:
This can be generalized to a method of Lagrange multipliers for maximizing/minimizing functions $f$ of three variables with two constraints $g=\hbox{const}$ and $h=\hbox{const}$. The method is based on the fact that $\grad{f}$, $\grad{g}$, and $\grad{h}$ must lie in a plane at a local maximum/minimum.
Lagrange multipliers can be used when solving absolute maximum/minimum problems in order to find the extreme values on the boundary. This is done by viewing the equation of the boundary as the constraint.