core21 min studyLesson 16 in Mathematics

Constrained optimization

Find extrema along feasible directions and use Lagrange multipliers without confusing candidates with guarantees.

Before you begin
On this page

What you’ll understand

  • Distinguish feasible motion from arbitrary motion.
  • Derive multiplier equations at a regular equality constraint.
  • Verify candidate optima using geometry, boundaries, or convexity.

An optimizer rarely gets to choose every variable independently. A design may have a fixed material budget, a probability vector must sum to one, and a normalized quantum state has a fixed norm. The right question is therefore whether the objective can improve along an allowed direction. Lagrange multipliers express this geometry compactly. They produce candidate solutions under stated regularity conditions; a separate argument must establish which candidate is best and whether the optimum exists.

Feasible directions change the stationarity condition

For an unconstrained smooth minimum inside an open region, the gradient must vanish because every sufficiently small direction is allowed. Under an equality constraint g(x)=cg(x)=c, a feasible tangent direction vv instead satisfies ∇g⋅v=0\nabla g\cdot v=0. At a constrained stationary point, the objective has no first-order change in any such tangent direction. Its gradient can be nonzero while pointing entirely across the constraint surface.

With one smooth constraint and ∇g≠0\nabla g\ne0, a vector perpendicular to all feasible tangent directions must be parallel to the constraint gradient. This gives the multiplier equation. If the constraint gradient vanishes, that reasoning breaks down, and singular points need direct examination. For multiple equalities, the corresponding gradients must be independent to use the same regularity argument cleanly.

∇f(x)=λ∇g(x),g(x)=c\nabla f(x)=\lambda\nabla g(x),\qquad g(x)=c
These are necessary conditions for a smooth equality-constrained local extremum at a regular point with ∇g≠0. They identify candidates, not automatically minima.↔ Scroll wide equations horizontally.

The Lagrangian organizes the equations

Define a Lagrangian by subtracting a multiplier times the constraint residual. Stationarity with respect to the original variables gives the parallel-gradient equation, while stationarity with respect to the multiplier restores feasibility. The sign convention is arbitrary if used consistently. The multiplier is an auxiliary unknown, not an extra design freedom that permits violating the constraint. Solve the objective and feasibility equations together.

A multiplier can also measure sensitivity. Under suitable smoothness and an isolated smoothly varying optimum, the derivative of the optimal objective with respect to the constraint level equals the multiplier for this sign convention. This shadow-price interpretation is local and depends on the parameterization of the constraint. Multiplying the constraint equation by a constant rescales the multiplier even though it leaves the feasible set unchanged.

L(x,λ)=f(x)−λ(g(x)−c),∇xL=0,∂λL=0\mathcal L(x,\lambda)=f(x)-\lambda\bigl(g(x)-c\bigr),\qquad \nabla_x\mathcal L=0,\quad \partial_\lambda\mathcal L=0
The residual g(x)−c must vanish. With this minus-sign convention, a regular differentiable optimal-value branch satisfies d f*/dc=λ.↔ Scroll wide equations horizontally.

Verification belongs to the solution

After solving the multiplier equations, compare candidates and inspect relevant boundaries or singular points. On a compact feasible set, a continuous objective attains a maximum and minimum, but those extrema can have different values. On an unbounded set, a stationary point need not be globally best and an optimum might not exist. Substituting the constraint into the objective is often the simplest independent check in a two-variable example.

Convexity can provide a stronger guarantee. A convex objective minimized over an affine set has no worse local minima hidden elsewhere; strict convexity gives uniqueness when a minimizer exists. Inequality constraints require additional logic, including active constraints and complementary slackness in the KKT framework. We have not derived that framework here. In machine learning, a nonconvex loss or a normalization constraint must be analyzed on its own terms rather than declared solved by writing a Lagrangian.

Split a fixed total at minimum squared cost

Minimize f(x,y)=x2+y2f(x,y)=x^2+y^2 subject to x+y=6x+y=6, allowing real x and y.

  1. Let g=x+yg=x+y. Its gradient (1,1)(1,1) never vanishes, so the regular multiplier equations apply: (2x,2y)=λ(1,1)(2x,2y)=\lambda(1,1) with x+y=6x+y=6.

  2. The two gradient components give x=yx=y. Feasibility then gives x=y=3x=y=3, with λ=6\lambda=6 and objective value 1818.

  3. Verify globally by writing x2+(6−x)2=2(x−3)2+18x^2+(6-x)^2=2(x-3)^2+18. The square is nonnegative for every feasible real x, so no other point has smaller cost.

The result

The unique minimum is (3,3) with cost 18. More generally the minimum at total c is c²/2, whose derivative at c=6 equals the multiplier 6.

Explore the model

Interactive lab

Interactive lab · optimization

Inspect steps before trusting an optimizer

Vary step size η\eta and initial coordinate x0x_0 in gradient descent on f(x)=x2/2f(x)=x^2/2, then pause and step through the exact updates. Compare small steps with unstable η>2\eta>2. This unconstrained one-dimensional model does not enforce x+y=6 or solve multiplier equations; feasibility in this lesson is checked algebraically.

Inspect steps before trusting an optimizerGradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Current readings: Position x0: 2; Objective x²/2: 2; Iteration behavior: Stable step. All parameters are adjustable with the labeled controls below.−4−202402.174.356.528.7Parameter xf(x) = x²/2n = 0
ObjectiveDiscrete iterate
Position x0
2
Objective x²/2
2
Iteration behavior
Stable step
n = 0 · t = 0 s

Gradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forAn attractive descent animation is not evidence that constraints or global optimality have been satisfied.

Check your understanding

At a regular constrained minimum, why can the objective gradient be nonzero?

Try it yourself

Maximize the area xyxy subject to x+y=10x+y=10 and x,y≥0x,y\ge0. Check both the interior and boundary.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Substitute y=10−x and complete the square on the interval from 0 to 10.

Compare with the solution

The area is x(10−x)=25−(x−5)2x(10-x)=25-(x-5)^2. Its largest value is 25 at x=y=5x=y=5. The endpoints (0,10)(0,10) and (10,0)(10,0) both give zero, so checking them confirms that the interior candidate is the global maximum on the closed feasible interval.

Take it with you

  • Constrained stationarity concerns feasible tangent directions.
  • Multiplier equations require regularity and produce candidates.
  • A complete answer verifies feasibility, boundaries, and the claimed local or global guarantee.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.