The extrema of a function under a constraint can be found using the method of Lagrange multipliers. A condition for an extremum can be expressed by , which means that the level curve gradient and the constraint gradient are parallel. The scalar is called a Lagrange multiplier.
This Demonstration illustrates this method for over 150 different combinations of functions and constraints. It shows the relationship between the normalized level curve gradient and the normalized constraint gradient . The image on the left shows the level curves of the function and the constraint , while the image on the right shows the 3D view of the surface , with the constraint curve projected onto the surface. Use the slider to move the point around the constraint curve to observe the relation between the level curve and the constraint gradients as the point reaches an extremum. The movable point turns from green to red when the two vectors are parallel, signifying that the point is near a local extremum.
Extrema are detected by computing the value of the dot product of the normalized level curve gradient and the normalized tangent of the constraint curve. The point changes from green to red as the absolute value of the dot product approaches zero. The dot product equals zero if and only if the level curve gradient is perpendicular to the tangent vector of the constraint curve, that is, parallel to the constraint gradient.
Extrema that occur on singular points of the surface or constraint may not be detected by the Lagrange multiplier method.
The constraint curve data used comes from the collection of curves available in the Wolfram Language.