Exercises — Lagrange multipliers for constrained optimization
This page is a self-test. Every problem below has a collapsible solution — try it yourself first, then open the callout to check your full reasoning. Problems climb from recognition (spot the setup) to mastery (build something new). Each is tagged L1–L5.
Everything here builds on the parent note. If a step confuses you, re-read the derivation there. We reuse exactly one machine, over and over:
Here is the whole picture in one image. Everything on this page is a variation of it: the objective's contour lines (blue), the constraint curve (orange), and the special point where they just kiss — where their gradient arrows line up.

Level 1 — Recognition
Goal: read a problem and correctly write down the Lagrangian and the three equations. No heavy algebra.
Exercise 1.1
Write the Lagrangian for: minimize subject to . Then write the three equations you would solve. (Do not solve them.)
Recall Solution 1.1
What we do: plug straight into the machine. Here . The three equations (two gradient equations + the constraint): That is it — three equations, three unknowns . The third equation is .
Exercise 1.2
Which of these is a valid Lagrangian for "maximize subject to "? Pick and explain. (a) (b) (c)
Recall Solution 1.2
Answer: (b). The constraint must be written as , i.e. , so that setting gives back exactly .
- (a) drops the , so forces — the wrong constraint.
- (c) multiplies by instead of adding a -term. Then , which is nonsense as a constraint recovery. The multiplier must enter linearly and additively.
Level 2 — Application
Goal: run the machine end-to-end and get numbers.
Exercise 2.1
Minimize subject to . Find and the minimum value.
Recall Solution 2.1
Step 1 — Lagrangian. () Step 2 — gradient equations. Step 3 — substitute into the constraint : So , . Minimum value: . Geometry: is the point on the line closest to the origin — the foot of the perpendicular from .
Exercise 2.2
Maximize subject to . Find and the max value.
Recall Solution 2.2
Step 1. . Step 2. Step 3. Substitute into : So , . Max area . Sanity: the two terms and each equal — the product is maximized when the constraint's two "weighted halves" are equal. That's a recurring pattern.
Level 3 — Analysis
Goal: interpret , handle the sensitivity/shadow-price meaning, deal with quadratic-vs-linear structure.
Exercise 3.1
For minimize subject to , find the optimum as a function of , find , and verify the sensitivity relation .
Recall Solution 3.1
Solve in general. . Constraint: . So . Optimal value: Sensitivity check: Meaning: is the shadow price — the rate at which the best achievable value changes as you loosen the constraint by one unit. Here relaxing by raises by about .

Exercise 3.2
In Exercise 2.2 you found at . Predict the new maximum area if the budget rises from to , using . Then compute the exact new area and compare.
Recall Solution 3.2
Prediction using : , so predicted new area . Exact recompute at : same algebra gives , and , so , . Compare: predicted vs exact . Close — the multiplier gives a first-order (linear) estimate; the small gap () is the curvature the linear prediction misses.
Level 4 — Synthesis
Goal: combine tools — multiple constraints, symmetry, an SVM-flavored problem.
Exercise 4.1 (two constraints)
Minimize subject to both and . Find the point and both multipliers.
Recall Solution 4.1
Two constraints ⇒ two multipliers. With and : Gradient equations: Constraints: , . From and the equations: subtract them, Then and both give , and gives , so . Constraint . Thus . Multipliers: , . Interpretation of : the symmetry constraint is "free" here — the unconstrained-on-that-axis optimum already satisfies it, so relaxing it changes nothing.
Exercise 4.2 (SVM-style)
Minimize subject to . Find , , and .
Recall Solution 4.2
This is the SVM shape: smallest-norm weight vector meeting a linear margin condition. Gradients: So — the weight vector points along the constraint's coefficient vector . That is the whole geometric moral of SVMs: the min-norm solution is parallel to the constraint normal. Constraint: . So , and , giving .
Level 5 — Mastery
Goal: reason about when the method breaks, and build a full argument from scratch.
Exercise 5.1 (degenerate gradient)
Try to minimize subject to . Set up the Lagrangian equations and explain why the method fails here.
Recall Solution 5.1
Setup. . Gradients: The constraint forces (only the origin has zero radius). Where it breaks: at , — the constraint gradient is the zero vector. The condition becomes , i.e. , which is impossible for any . Why this matters: the Lagrange condition secretly assumes at the optimum (a "regularity" / constraint-qualification condition). When , the constraint surface has no well-defined tangent direction and the alignment argument collapses. Lesson: always check at candidate points. This same regularity requirement reappears in the KKT conditions for inequality constraints.
Exercise 5.2 (build it yourself)
A rectangular box has a fixed surface area . Derive the dimensions that maximize its volume, using Lagrange multipliers. (Box with sides : volume , surface area .)
Recall Solution 5.2
Objective and constraint. Lagrangian. Gradients: Solve by symmetry. Multiply the first by , second by , third by : From (with ): (since ). Likewise . So — a cube. Apply the constraint: . So , volume , and : from , . Result: the maximum-volume box for a given surface area is a cube — the 3-D cousin of "square maximizes area for fixed perimeter."
Recall Quick self-check (clozes)
The extra equation you must never forget is ::: the constraint , i.e. equals the derivative of the optimal value with respect to ::: the constraint constant (the shadow price ) With constraints you need this many multipliers ::: The hidden assumption behind is ::: at the optimum (constraint qualification / regularity)
Where to go next: inequality constraints generalize all of this via the KKT conditions; the shadow-price idea becomes duality; the min-norm structure of Exercise 4.2 is the heart of Support Vector Machines; and the " plus a penalty" viewpoint links to Regularization, Penalty Methods, and Convex Optimization. To reach these optima numerically, see Gradient Descent.