Unconstrained optimization hunts for places where the gradient of an objective $f$ is zero. A constraint $g(\mathbf{x})=c$ changes the hunt. You may only travel on the level set of $g$. The best value of $f$ on that set usually occurs where you can no longer climb $f$ without leaving the set. That is a tangency picture, not a new kind of calculus. The number that records the tangency is a Lagrange multiplier.

At a constrained local max or min, when $\nabla g$ is not zero, $\nabla f$ is parallel to $\nabla g$. So there is a number $\lambda$ with

$$\nabla f=\lambda\nabla g, \qquad g=c.$$

The vector equation says the two gradients line up. The scalar equation says you stayed on the constraint. Together they are usually $n+1$ equations in $n+1$ unknowns when $\mathbf{x}$ lives in $\mathbb{R}^n$. This page sits in the multivariable cluster of the explainer library, after gradients. The topic map is multivariable and vector calculus. The pathway that this site uses before that cluster is the linear algebra first course, because a gradient is a vector and a Jacobian of two gradients is a matrix.

Why parallelism is the right demand

On the constraint, allowed motions are tangent to $g=c$. Those tangent directions are exactly the directions orthogonal to $\nabla g$, provided $\nabla g\neq\mathbf{0}$. If $\nabla f$ still has a piece along an allowed tangent, you can slide a little and change $f$. At an interior optimum on the constraint, $\nabla f$ must have no tangent component left. The only remaining possibility is that $\nabla f$ is a multiple of $\nabla g$.

Read the same fact with a dot product. Let $\mathbf{t}$ be any tangent vector to the constraint at the point. Then $\nabla g\cdot\mathbf{t}=0$. Parallelism says $\nabla f\cdot\mathbf{t}=0$ as well. The directional derivative of $f$ along every allowed direction is zero. That is the constrained version of "the derivative is zero," and it is weaker than $\nabla f=\mathbf{0}$. You are not required to be flat in the directions that the constraint forbids.

You can estimate that slope on the gradient and directional derivative calculator. Type the objective, the point, and a tangent to the constraint. At a candidate the directional derivative along that tangent should come out near zero, because the gradient of $f$ is parallel to the gradient of $g$ and the tangent is perpendicular to both.

Level sets of $f$ make the same point in a drawing. You want the highest or lowest contour of $f$ that still touches $g=c$. Two curves that touch and do not cross share a tangent line. Their normals, which are the gradients, therefore line up. If the contours crossed, you could step onto a better contour of $f$ while remaining on $g=c$. Crossing is a failure of optimality. Tangency is the picture of a candidate.

This is the same geometry as on the multivariable pillar. A gradient is normal to a level set. Lagrange adds one rule. At the optimum, the level set of $f$ and the level set of $g$ should be tangent to each other.

A line you can also do by substitution

Example Maximize $f(x,y)=xy$ on the line $x+y=1$. Set $g(x,y)=x+y$, so $c=1$. Then $\nabla f=\langle y,x\rangle$ and $\nabla g=\langle 1,1\rangle$. Parallelism says $y=\lambda$ and $x=\lambda$, so $x=y$. The constraint then gives $x=y=1/2$, and $f=1/4$. There is one candidate.

Substitution agrees. Set $y=1-x$. Then $f(x)=x(1-x)=x-x^2$, and the ordinary derivative $1-2x$ is zero at $x=1/2$. The second derivative is $-2$, so this critical point is a maximum of the substituted function. On the whole line, which is not bounded, $f$ still runs to $-\infty$ as $x$ runs to $\pm\infty$, because $-x^2$ dominates. The Lagrange point is a maximum, and there is no minimum. The method found the candidate. The shape of the constraint told you which kind of extreme you had.

Here $\lambda=1/2$. That number is not a decoration. If you relax the constraint from $x+y=1$ to $x+y=1+\varepsilon$, the new maximum of $xy$ is $(1+\varepsilon)^2/4$. For small $\varepsilon$ that is about $1/4+(1/2)\varepsilon$. The coefficient of $\varepsilon$ is $\lambda$. In that sense $\lambda$ is a sensitivity. It measures how hard $f$ pulls against a small change in the allowed level of $g$. A first course can stop at that sentence. A zero multiplier would have meant the optimal value barely notices a small move of the constraint.

A circle, where substitution is less kind

Example Maximize and minimize $f(x,y)=xy$ on the unit circle $g(x,y)=x^2+y^2=1$. Now $\nabla f=\langle y,x\rangle$ and $\nabla g=\langle 2x,2y\rangle$. The system is

$$y=2\lambda x,\qquad x=2\lambda y,\qquad x^2+y^2=1.$$

If $x$ and $y$ are both nonzero, substitute $x=2\lambda y$ into the first equation: $y=2\lambda(2\lambda y)=4\lambda^2 y$. Then $4\lambda^2=1$, so $\lambda=\pm 1/2$. For $\lambda=1/2$ you get $y=x$, and the circle forces $x=y=\pm 1/\sqrt{2}$. Both points give $f=1/2$. For $\lambda=-1/2$ you get $y=-x$, and the points $(1/\sqrt{2},-1/\sqrt{2})$ and $(-1/\sqrt{2},1/\sqrt{2})$ give $f=-1/2$. If you try $x=0$, the second equation forces $y=0$, which is not on the circle. The same happens if $y=0$. So there are four candidates, and no others.

The circle is closed and bounded, and $f$ is continuous, so a max and a min exist. Comparing values, the maximum is $1/2$ and the minimum is $-1/2$. A substitution check uses $x=\cos\theta$ and $y=\sin\theta$. Then $xy=(1/2)\sin 2\theta$, whose range on a full turn is exactly $[-1/2,1/2]$. The multiplier method and the angle method name the same extremes.

The multiplier still has a job after the points are known. At a maximum, $\lambda=1/2$. Move the constraint to $x^2+y^2=1+\varepsilon$ with $\varepsilon$ small and positive, so the radius squared grows. The largest value of $xy$ on a circle of radius squared $r^2$ is $r^2/2$, because $(x+y)^2=r^2+2xy$ and the largest $|x+y|$ is $r\sqrt{2}$. So the new maximum is $(1+\varepsilon)/2=1/2+(1/2)\varepsilon$. Again the change is about $\lambda\varepsilon$. At a minimum, $\lambda=-1/2$, and the smallest value $-(1+\varepsilon)/2$ moves down as $\varepsilon$ grows, which matches a negative sensitivity.

What can go wrong

The method lists candidates. It does not, by itself, label them max, min, or neither. On a closed bounded constraint, such as a circle, an ellipse, or a sphere, a continuous $f$ attains its max and its min, so you evaluate $f$ at every Lagrange point and compare. On an unbounded constraint, as on the line above, values may run to infinity and a critical point may be only a local story. "I solved the system" is not the same sentence as "this point is the global maximum."

You also need $\nabla g\neq\mathbf{0}$ at the point. If the constraint is singular, the set of allowed tangents may be smaller than the orthogonal complement of $\nabla g$, or the level set may pinch. The parallelism condition can miss a genuine optimum or become vacuous. A standard picture is the constraint $x^2-y^2=0$, the pair of lines $y=\pm x$. At the origin, $\nabla g=\mathbf{0}$ if $g(x,y)=x^2-y^2$. Inspect that point by geometry. Do not trust a multiplier equation there.

Inequalities are a different problem. The equation $g=c$ is the boundary. The inequality $g\le c$ also has an interior, where the constraint is slack and you look for ordinary critical points $\nabla f=\mathbf{0}$. A first course that only writes $\nabla f=\lambda\nabla g$ and never mentions the interior will miss an optimum that sits inside the region. If the problem says "subject to $x^2+y^2\le 1$," do the disk interior and the circle, then compare.

Several constraints $g_1=c_1,\ldots,g_k=c_k$ replace the single $\lambda$ with a linear combination

$$\nabla f=\lambda_1\nabla g_1+\cdots+\lambda_k\nabla g_k,$$

provided the constraint gradients stay independent. Allowed motions are orthogonal to every $\nabla g_i$. Then $\nabla f$ must live in their span. Each $\lambda_i$ is a sensitivity to its own constraint level. If the constraint gradients are dependent, you have fewer genuine restrictions than the count $k$ suggests, and the list of multipliers is not unique.

Pitfall. Solving $\nabla f=\lambda\nabla g$ without $g=c$ finds a family of points that need not lie on the constraint. Always include the constraint equation. Also, $\lambda=0$ is allowed. It means $\nabla f=\mathbf{0}$ already, so an unconstrained critical point happens to lie on $g=c$. Dropping $\lambda=0$ because it "looks trivial" can drop the answer.

How this connects to derivatives you already know

If you can solve the constraint for $y=h(x)$, the problem becomes ordinary one variable calculus. Implicit differentiation is the engine when you need $h'(x)$ without a full formula for $h$. On the line example, $y=1-x$ is explicit, so implicit work is unnecessary. On the circle $x^2+y^2=1$, implicit differentiation gives $y'=-x/y$ when $y\neq 0$. The slope of $f(x,y)=xy$ along the curve is then an ordinary derivative of $x\,y(x)$. Lagrange is what you use when you would rather not solve, and when you want $\lambda$ as well as the point. Both methods, when they apply and the constraint is smooth, describe the same tangency.

The two gradients are parallel exactly when the matrix with rows $\nabla f$ and $\nabla g$ has determinant zero. That determinant is a $2$ by $2$ Jacobian of the map $(f,g)$. See Jacobian matrices in plain language. A zero determinant says the two gradient rows are dependent, which is the Lagrange condition in one line, still paired with $g=c$. It does not say which candidate wins.

Partials are the entries of those gradients. If a single partial feels shaky, hold the other variable fixed and read partial derivative before you build $\nabla f$. The single variable meaning of a derivative, as a best local rate, is what a derivative actually measures. A multiplier is not that rate. It is the rate of the optimal value with respect to the constraint level.

How to know you understood

  1. For $xy$ on $x+y=1$, produce the point $(1/2,1/2)$, the value $1/4$, and $\lambda=1/2$, and say why there is no minimum on the whole line.
  2. For $xy$ on the unit circle, list the four points and say which value is the max and which is the min.
  3. Explain $\lambda$ with the moved constraint. On the circle, say why the new maximum on $x^2+y^2=1+\varepsilon$ is about $1/2+(1/2)\varepsilon$.
  4. Give one reason a Lagrange point might not be a maximum, and one reason a point with $\nabla g=\mathbf{0}$ needs a separate look.
  5. Say what an inequality constraint adds, in one sentence: an interior search, not only the boundary system.

Check the geometry with the nearby tools

Nothing on this site solves a Lagrange system for you. That is deliberate. The algebra is the understanding. The calculators audit a vector fact you already set up.

Try it. At $(1/2,1/2)$ on the line $x+y=1$, the gradient of $f$ is $\langle 1/2,1/2\rangle$ and an allowed tangent is $\langle 1,-1\rangle$. Their dot product is $0$. Open the vector operations calculator in two dimensions and confirm that dot product. Then put the two gradients $\langle 1/2,1/2\rangle$ and $\langle 1,1\rangle$ in as rows of a matrix on the 2 by 2 matrix calculator. The determinant should be $0$, which is parallelism. On the unit circle at $(1/\sqrt{2},1/\sqrt{2})$, the same two checks work with $\nabla f=\langle 1/\sqrt{2},1/\sqrt{2}\rangle$ and a tangent $\langle -1,1\rangle$.

If you only want a numerical slope after you have solved for $y$ explicitly, the numerical derivative calculator can audit that one variable function. It cannot see a constraint. Use it as a check of substitution, not as a search for $\lambda$.

After you have a candidate, check that the objective gradient is perpendicular to an allowed tangent.

Open the vector operations calculator

A normal shows up again when a surface has an oriented boundary. That is a different theorem. Read Stokes theorem intuition only after line integrals and curl are already in your vocabulary. If you are still on a single variable path, stay with the AP Calculus AB bridge and return to multipliers when gradients are ordinary.

Citations and further reading