WhatsApp us
University Maths25 Nov 2026

Lagrange Multipliers Step by Step: Worked Examples With One and Two Constraints

A step-by-step method for Lagrange multipliers, from a single constraint to two constraints and closed regions, with six graded worked examples, the case-splitting that students miss, a method table and practice questions with answers.

Lagrange Multipliers Step by Step: Worked Examples With One and Two Constraints

Lagrange multipliers find the maximum and minimum of a function f subject to a constraint g = c. At an extreme point on the constraint, the gradients line up, so you solve ∇f = λ∇g together with g = c, then compare f at every solution. With two constraints the condition becomes ∇f = λ∇g + μ∇h.

The method is short to state, but most lost marks come from the algebra: dividing by a variable that can be zero, missing a case, or forgetting to compare values at the end. The examples below are graded so each one adds a single new difficulty.

Why the gradients must be parallel

Picture the level curves of f crossing the constraint curve g = c. Where a level curve cuts across the constraint, you can slide along the constraint and push f higher or lower, so that point is not an extreme. At a maximum or minimum, the level curve of f just touches the constraint, which means the two curves share a tangent line there. Gradients are perpendicular to level curves, so ∇f and ∇g point along the same line: ∇f = λ∇g. If the gradient and level-curve facts are new, our guide to partial derivatives and the gradient covers them first.

This tangency picture is exactly what Calculus III / Multivariable Calculus courses test. Our online advanced calculus tutoring page explains how sessions with Ajay Vatsyayan work through constrained optimisation on your own course.

The method in five steps

  1. Write the objective f and the constraint in the form g(x, y, z) = c.
  2. Compute ∇f and ∇g.
  3. Write the system: each component of ∇f = λ∇g, plus the constraint. With n variables you get n + 1 equations in n + 1 unknowns.
  4. Solve by splitting into cases. Never divide by an expression unless you have handled separately the case where it is zero.
  5. Evaluate f at every candidate point. The largest value is the maximum and the smallest is the minimum, provided the constraint set is closed and bounded.

Choosing your approach

SituationApproachWhy
Linear constraint, easy to solve for one variableSubstitute, then one-variable calculusFewer equations, as in single-variable optimisation problems
Constraint is a circle or ellipse in 2DParametrise (x = r cos t, ...) or LagrangeBoth work; Lagrange avoids trig identities
Symmetric objective and constraintLagrangeThe equations often force x = y = z quickly
Two constraints in 3DLagrange with λ and μSubstitution is usually messy
Optimise over a closed regionInterior critical points plus Lagrange on the boundaryExtremes can be inside or on the edge
Inequality constraints in economics or machine learningKKT conditionsThe general version of Lagrange

Six worked examples

Example 1: one constraint, one solution

Maximise f(x, y) = xy subject to 2x + 5y = 40 with x, y > 0.

∇f = (y, x) and ∇g = (2, 5). The system is

y = 2λ, x = 5λ, 2x + 5y = 40

Substituting: 10λ + 10λ = 40, so λ = 2, giving x = 10, y = 4 and f = 40.

Why a maximum? On the segment, f is 0 at both ends (x = 0 or y = 0) and positive in between, so the single interior candidate is the maximum.

Example 2: case splitting on a circle

Find the extreme values of f(x, y) = x² + 2y² − 2x on the circle x² + y² = 4.

∇f = (2x − 2, 4y), ∇g = (2x, 2y). The equations are

2x − 2 = 2λx

4y = 2λy

x² + y² = 4

The second equation is 2y(2 − λ) = 0, so y = 0 or λ = 2. Do not divide by y.

Case y = 0: then x = ±2. f(2, 0) = 4 − 4 = 0 and f(−2, 0) = 4 + 4 = 8.

Case λ = 2: the first equation becomes 2x − 2 = 4x, so x = −1 and y² = 3. f(−1, ±√3) = 1 + 6 + 2 = 9.

Compare all four candidates: the maximum is 9 at (−1, ±√3) and the minimum is 0 at (2, 0). The point (−2, 0) with f = 8 is a candidate but neither extreme, which is why step 5 matters.

Example 3: three variables and a cost problem

A closed box must hold volume 54. The base material costs 3 per unit area and the top and four sides cost 1 per unit area. Find the dimensions of least cost.

With base x by y and height z, the cost is C = 3xy + xy + 2xz + 2yz = 4xy + 2xz + 2yz, subject to xyz = 54.

∇C = λ∇g gives

4y + 2z = λyz

4x + 2z = λxz

2x + 2y = λxy

Multiply the first by x and the second by y: both right-hand sides become λxyz, so 4xy + 2xz = 4xy + 2yz, which gives x = y (as z > 0). The third equation becomes 4x = λx², so λ = 4/x. Put that into the first: 4x + 2z = 4z, so z = 2x.

Then x · x · 2x = 54, so x³ = 27 and x = 3. The box is 3 by 3 by 6, with cost 36 + 36 + 36 = 108.

The trick of multiplying equations to create a common λxyz is worth remembering; it appears in most box questions.

Example 4: nearest points on a surface

Find the points of the surface z² = xy + 4 nearest the origin.

Minimise the squared distance f = x² + y² + z² (same minimiser, simpler derivatives) subject to g = z² − xy = 4.

2x = −λy

2y = −λx

2z = 2λz

The third equation gives z = 0 or λ = 1.

Case λ = 1: 2x = −y and 2y = −x force x = y = 0, so z² = 4 and z = ±2. Here f = 4.

Case z = 0: then xy = −4, so x and y are non-zero. From the first two equations x = λ²x/4, so λ = ±2. With λ = 2, y = −x, so −x² = −4 and x = ±2, giving (2, −2, 0) and (−2, 2, 0) with f = 8. With λ = −2, y = x, so x² = −4, which has no real solution.

The nearest points are (0, 0, ±2), at distance 2. The surface is unbounded, so there is no farthest point; the argument for a minimum is that f grows without limit far from the origin.

Example 5: two constraints

Find the highest and lowest points on the curve where the cylinder x² + y² = 2 meets the plane x + y + z = 4.

Objective f = z, constraints g = x² + y² = 2 and h = x + y + z = 4. The condition is ∇f = λ∇g + μ∇h:

0 = 2λx + μ

0 = 2λy + μ

1 = μ

So μ = 1 and x = y = −1/(2λ). The cylinder gives 2x² = 2, so x = y = ±1.

x = y = 1 gives z = 2. x = y = −1 gives z = 6.

The highest point is (−1, −1, 6) and the lowest is (1, 1, 2). The curve is an ellipse, which is closed and bounded, so both extremes exist.

Example 6: a closed region, not just its edge

Find the extreme values of f(x, y) = x² + 2y² − 2x on the disc x² + y² ≤ 4.

Inside the disc: ∇f = (2x − 2, 4y) = 0 gives (1, 0), with f = −1.

On the boundary circle: this is Example 2, with candidates 0, 8 and 9.

Comparing: the maximum is 9 on the boundary and the minimum is −1 at the interior point (1, 0). Using Lagrange alone would have reported 0 as the minimum, which is wrong for the disc.

What λ tells you

λ measures how fast the optimal value changes as the constraint level c changes. In Example 1, the maximum of xy on 2x + 5y = c is c²/40, whose derivative at c = 40 is 2, matching λ = 2. Raising the budget from 40 to 41 raises the largest possible product by about 2. Economics courses call this a shadow price; physics uses multipliers as constraint forces.

When the method fails

The theorem needs ∇g ≠ 0 at the extreme point. Minimise f = x on the curve y² = x³. The curve has a cusp at the origin, and since x = y^(2/3) ≥ 0, the minimum is 0 at (0, 0). But the Lagrange equations 1 = −3λx², 0 = 2λy, y² = x³ have no solution at all: λ ≠ 0 forces y = 0, then x = 0, then 1 = 0. The minimum sits exactly where ∇g = (0, 0), so always check points where ∇g vanishes as extra candidates.

Where students lose marks

  • Dividing by a variable. In Example 2, cancelling y from 4y = 2λy loses the points (±2, 0), including the minimum. Factor instead: 2y(2 − λ) = 0.
  • Stopping after solving. Lagrange gives candidates, not answers. List f at every candidate before naming the maximum and minimum.
  • Forgetting the interior. For a region such as x² + y² ≤ 4, find critical points inside as well.
  • Claiming a maximum on an unbounded set. In Example 4, only a minimum exists. Say why an extreme exists before naming it.
  • Using one multiplier for two constraints. Each constraint needs its own multiplier: ∇f = λ∇g + μ∇h.
  • Minimising the distance itself. Minimise the squared distance; the square root only adds messy derivatives.

Practice questions

  1. Find the extreme values of f = x²y on x² + y² = 3.
  2. Find the point on the plane 2x − y + 2z = 18 nearest the origin.
  3. Find the maximum and minimum of x + y + z on the ellipsoid x² + 2y² + 4z² = 7.
  4. Find the extreme values of x² + y² on the region x² + xy + y² ≤ 3.
  5. Maximise xyz for positive x, y, z with x + 2y + 3z = 18.

Answers:

  1. Maximum 2 at (±√2, 1); minimum −2 at (±√2, −1).
  2. (4, −2, 4), at distance 6.
  3. Maximum 7/2 at (2, 1, ½); minimum −7/2 at (−2, −1, −½).
  4. Minimum 0 at the origin; maximum 6 at (√3, −√3) and (−√3, √3).
  5. 36, at (6, 3, 2).

Where this leads next

Question 4 is linear algebra in disguise. On the unit circle x² + y² = 1, the extreme values of a quadratic form xᵀAx are the eigenvalues of the symmetric matrix A, and the multipliers equal those eigenvalues. In Question 4, A has entries 1, ½, ½, 1 with eigenvalues 3/2 and ½, and 3 ÷ (3/2) = 2 and 3 ÷ ½ = 6 are exactly the boundary values. Multivariable courses then move to double and triple integrals in polar, cylindrical and spherical coordinates. Beyond calculus, the same idea becomes the KKT conditions in optimisation, support vector machines in machine learning, and constrained utility and cost problems in economics. Engineering students meet it in design and control, which our engineering maths tutoring covers.

How Maths Bodhi helps

Students we teach usually set up ∇f = λ∇g correctly and then lose a case in the algebra. Sessions practise the case-splitting habit on your own course's problem sets and review your attempts step by step. We explain and practise; we don't complete graded assignments or exams. US students can see how this fits Calculus III on our college maths tutoring page, and other students on our university maths overview.

Home tuition is available in Gurgaon (Gurugram). Students elsewhere in India and abroad learn with us online. You can book a free demo class.

Written and checked by the Maths Bodhi team (November 2026).

Frequently asked questions

How do you use Lagrange multipliers step by step?
Solve ∇f = λ∇g together with the constraint, then evaluate f at every solution and compare.
How do Lagrange multipliers work with multiple constraints?
Add one multiplier per constraint, so with two constraints solve ∇f = λ∇g + μ∇h plus both constraint equations.
Does Lagrange always give a maximum and a minimum?
Only when the constraint set is closed and bounded; on an unbounded set one or both may not exist.
What does the Lagrange multiplier λ mean?
It is the rate at which the optimal value changes as the constraint level changes, often called a shadow price.
Do I need to check the interior of a region?
Yes, for a region like a disc, find critical points inside and use Lagrange only on the boundary.
Why did I miss a solution?
Usually by dividing by a variable that can be zero; factor the equation and treat each case separately.
Lagrange multipliersconstrained optimisationmultivariable calculuscalculus 3gradient

Related guides

Keep exploring this maths topic

University Maths18 Nov 2026

Partial Derivatives, the Gradient and Directional Derivatives: Worked Examples

How to find partial derivatives, use the multivariable chain rule, build the gradient and compute directional derivatives, with six graded worked examples, a method table, common mistakes and a practice set with answers.

partial derivativesgradientdirectional derivativemultivariable calculus

By Maths Bodhi Team

Read guide

University Maths25 Nov 2026

Triple Integrals in Spherical Coordinates (and Polar and Cylindrical): Worked Examples

How to choose between polar, cylindrical and spherical coordinates, where the Jacobian factors r and ρ² sin φ come from, how to set the limits, and six graded worked examples with practice questions and answers.

triple integralsspherical coordinatespolar coordinatescylindrical coordinates

By Maths Bodhi Team

Read guide

University Maths25 Nov 2026

Line Integrals of Vector Fields and Conservative Fields: Worked Examples

How to compute scalar and vector line integrals, how to test whether a vector field is conservative, how to find a potential function and use the fundamental theorem for line integrals, with six graded worked examples and practice answers.

line integralsconservative vector fieldspotential functionmultivariable calculus

By Maths Bodhi Team

Read guide

University Maths2 Nov 2026

Green's, Stokes' and the Divergence Theorem: Which One to Use, With Worked Examples

How Green's theorem, Stokes' theorem and the divergence theorem connect, a decision table for choosing one, six graded worked examples with every step, orientation rules, common mistakes and practice questions with answers.

vector calculusGreen's theoremStokes' theoremdivergence theorem

By Maths Bodhi Team

Read guide

University Maths25 Nov 2026

Optimization Problems in Calculus: Setup, Worked Examples and Practice

How to set up and solve optimization problems in Calculus I, how to justify that an answer is the absolute maximum or minimum, six worked examples from fencing to a river crossing, the errors that lose marks and practice with answers.

optimizationCalculus Iapplications of derivativesmaxima and minima

By Maths Bodhi Team

Read guide