MULTIVARIABLE CALCULUS • OPTIMIZATION IN SEVERAL VARIABLES

Constrained Optimization — Optimize with constraints and interpret results

Learn how to find the best possible outcome when real-world limitations restrict your choices.

Historical Context & Motivation

📌 Prerequisites & Placement Note
This lesson introduces constrained optimization using Lagrange multipliers, a college-level topic from Multivariable Calculus (Calculus III). It goes beyond AP Calculus AB and BC, which do not cover multivariable functions, partial derivatives, or gradient vectors. To get the most from this lesson, you should be comfortable with single-variable calculus (derivatives, the chain rule) and algebra (solving systems of equations). Key new ideas—partial derivatives, gradients, and level curves—are explained step by step as they appear.

Throughout history, people have faced a fundamental challenge: how do you get the best result when you have limited resources? Whether a farmer wants to maximize crop yield with a fixed amount of land, or an engineer needs to minimize the weight of a bridge while keeping it strong enough, the problem is the same. You want to optimize something, but real-world constraints limit what you can do. The branch of mathematics that handles this is called constrained optimization, and it sits at the heart of multivariable calculus.

1788
Lagrange's Analytical Mechanics
Joseph-Louis Lagrange published his masterwork on mechanics, introducing the idea of using multipliers to handle constraints in physical systems—an idea that would eventually bear his name.
1797
Lagrange Multipliers Formalized
Lagrange refined his technique of introducing an auxiliary variable (the Lagrange multiplier) to convert constrained problems into systems of equations, making them solvable with calculus.
1939
Linear Programming Emerges
Leonid Kantorovich developed methods for optimizing linear functions subject to linear constraints, laying the groundwork for operations research used in logistics and economics.
1951
Kuhn-Tucker Conditions
Harold Kuhn and Albert Tucker extended Lagrange's ideas to handle inequality constraints, broadening the toolkit for real-world optimization problems in engineering and economics.
Today
Machine Learning & AI
Modern artificial intelligence algorithms use constrained optimization constantly—from training neural networks to designing self-driving car routes, Lagrange's 18th-century idea powers 21st-century technology.

The central question that constrained optimization answers is deceptively simple: if you have a function you want to maximize or minimize, but you are restricted to only certain inputs, how do you find the best possible value? Before Lagrange's method, mathematicians often had to resort to substitution, which becomes messy or impossible for complex constraints. Lagrange's elegant insight was that at the optimal point, the gradient of the objective function must be proportional to the gradient of the constraint. Don't worry if those terms are unfamiliar—we will build up to them carefully in the next section. This single idea transformed how we solve optimization problems across every field of science.

Core Principles & Definitions

🔑 New Vocabulary Ahead
This section introduces several new vocabulary words. Read each definition carefully before moving on. Every term is explained from the ground up—no prior multivariable calculus is assumed.

In single-variable calculus you worked with functions like f(x) = x². In multivariable calculus, functions can depend on two or more inputs. For example, f(x, y) = x² + y² takes a pair of numbers (x, y) and outputs a single value—like the temperature at every point on a flat surface. The objective function is the function you want to optimize (maximize or minimize). The constraint is a condition that limits which inputs (x, y) you are allowed to use. For instance, if you must stay on a circular path of radius 1, then x² + y² = 1 is your constraint.

📐 Building Block: Partial Derivatives
What is a partial derivative? When a function depends on two variables x and y, a partial derivative measures how the function changes when you vary just one variable while holding the other fixed. For example, if f(x, y) = x² + 3y, then the partial derivative with respect to x (written ∂f/∂x) treats y as a constant and differentiates: ∂f/∂x = 2x. The partial derivative with respect to y treats x as a constant: ∂f/∂y = 3. These are the same rules you already know from single-variable calculus, applied one variable at a time.
🧭 Building Block: The Gradient Vector
What is a gradient? The gradient of a function f(x, y), written ∇f (read "del f" or "grad f"), is simply a pair (a vector) made from the two partial derivatives: ∇f = ⟨∂f/∂x, ∂f/∂y⟩. You can think of it as a compass arrow that points in the direction where f increases most steeply—like the uphill direction on a hillside. For f(x, y) = x² + 3y, the gradient is ∇f = ⟨2x, 3⟩.
1

Objective Function f(x, y)

The quantity you want to maximize or minimize. It assigns a numerical value to every point in your domain, like profit, distance, or temperature. Example: f(x, y) = 2x + 5y might represent revenue.
2

Constraint g(x, y) = k

A condition that restricts your inputs to a specific curve or surface. Only points satisfying the constraint are valid candidates for the optimum. Example: x² + y² = 1 restricts you to a circle of radius 1.
3

Gradient ∇f

A vector built from the two partial derivatives: ∇f = ⟨∂f/∂x, ∂f/∂y⟩. It points in the direction of steepest increase of f. Think of it as the "uphill arrow" for the function.
4

Lagrange Multiplier λ

An extra unknown number introduced to link the objective function and constraint. At the optimum, ∇f = λ∇g. The value of λ tells you how sensitive the best outcome is to relaxing the constraint.
5

Level Curves

Curves along which a function has a constant value—like contour lines on a topographic map where every point on one contour is at the same elevation. At the constrained optimum, a level curve of f is tangent to the constraint curve.
KEY TAKEAWAY
Think of constrained optimization like hiking to the highest point you can reach while staying on a trail. You can't wander freely across the mountainside—you must follow the path. The Lagrange multiplier method finds the exact spot on the trail where the elevation is greatest. Mathematically, this happens where the trail's direction becomes perpendicular to the slope of the mountain, meaning the trail is running along a contour line rather than climbing or descending.

Visual Explanation — Gradients and Tangency

The dashed purple ellipses are level curves of the objective function f(x, y)—think of them like the elevation contour lines on a map, with values increasing toward the center. The solid gold curve is the constraint (the path you must stay on). At the optimum (green dot), the constraint curve just touches—is tangent to—a level curve of f. At that same point, the gradient arrow ∇f (cyan, pointing uphill for f) and the gradient arrow ∇g (pink, pointing away from the constraint curve) line up in the same direction. This alignment is the geometric meaning of ∇f = λ∇g.

The diagram above reveals the geometric insight behind constrained optimization. Imagine walking along the gold constraint curve and measuring the value of f at each point. As you walk, f increases until you reach the green dot, and then f starts decreasing. At that peak, the constraint curve is running along a level curve of f rather than crossing through it. This tangency condition means the gradient of f is perpendicular to the constraint curve at that point—but the gradient of g is also perpendicular to the constraint curve. Therefore, ∇f and ∇g must be parallel, which is exactly what ∇f = λ∇g says. The scalar λ is just the ratio of their lengths—it scales one gradient to match the other.

Mathematical Framework — The Lagrange Multiplier Method

Now let's formalize the geometric intuition into a step-by-step algebraic method. Suppose you want to optimize f(x, y) subject to the constraint g(x, y) = k. The method of Lagrange multipliers converts this into a system of equations by introducing the extra unknown λ (lambda). The key condition ∇f = λ∇g means: the gradient ("uphill arrow") of f equals λ times the gradient of g. Since each gradient has two components (one for x, one for y), this one vector equation actually contains two separate equations.

LAGRANGE CONDITION
∇f = λ · ∇g
∇f = ⟨∂f/∂x, ∂f/∂y⟩ is the gradient of the objective function (the vector of its two partial derivatives); ∇g = ⟨∂g/∂x, ∂g/∂y⟩ is the gradient of the constraint; λ is the Lagrange multiplier, an unknown number that scales one gradient to match the other.
SYSTEM OF EQUATIONS
∂f/∂x = λ · ∂g/∂x, ∂f/∂y = λ · ∂g/∂y, g(x, y) = k
Writing out the two components of ∇f = λ∇g plus the original constraint gives three equations in three unknowns: x, y, and λ. Solve this system to find the candidate points for the constrained maximum or minimum. This is ordinary algebra once you have computed the partial derivatives.
LAGRANGIAN FUNCTION
L(x, y, λ) = f(x, y) − λ · (g(x, y) − k)
An equivalent approach: define the Lagrangian function L by combining f and g into a single expression. Setting all three partial derivatives of L equal to zero (∂L/∂x = 0, ∂L/∂y = 0, ∂L/∂λ = 0) produces exactly the same system of three equations as above.
💡 Interpreting λ
The Lagrange multiplier λ has a practical meaning: it tells you approximately how much the optimal value of f would change if you slightly relaxed the constraint. For instance, if λ = 5 and you change the constraint from g(x, y) = 10 to g(x, y) = 11, the optimum of f changes by roughly 5 units. This makes λ a sensitivity measure—extremely valuable in economics and engineering.

Step-by-Step Process & Flowchart

Solving a constrained optimization problem follows a clear sequence. The flowchart below shows every decision and calculation in order. After working through several problems, this process will become second nature.

This flowchart summarizes the complete Lagrange multiplier process. Steps 1–4 set up the equations. Step 5 is the algebraic heart of the method. Steps 6–7 identify the answer. Step 8 adds deeper understanding by interpreting the multiplier.
  1. Step 1: Clearly identify the objective function f and write the constraint in the form g(x, y) = k.
  2. Step 2: Compute the partial derivatives to find ∇f = ⟨fx, fy⟩ and ∇g = ⟨gx, gy⟩. Remember: differentiate with respect to one variable at a time, treating the other as a constant.
  3. Steps 3–4: Write fx = λgx, fy = λgy, and g(x, y) = k. You now have three equations and three unknowns (x, y, and λ).
  4. Steps 5–7: Solve the system (often by dividing the first two equations to eliminate λ), then plug candidate points back into f to determine which gives the maximum and which gives the minimum.
  5. Step 8: Interpret λ: it approximates the rate of change of the optimal value with respect to the constraint constant k. A larger |λ| means the optimum is more sensitive to changes in the constraint.

Worked Example — Maximizing a Function on a Circle

Let's work through a complete problem from start to finish. Every computation is shown in full so you can follow along. Problem: Find the maximum and minimum values of f(x, y) = x² + 4y² subject to the constraint x² + y² = 1 (a unit circle—the set of all points exactly 1 unit from the origin).

Maximize f(x, y) = x² + 4y² subject to x² + y² = 1
1
Step 1 — Identify the functionsThe objective function is f(x, y) = x² + 4y². The constraint is g(x, y) = x² + y² with k = 1. We want to find points on the unit circle where f reaches its largest and smallest values.
2
Step 2 — Compute the partial derivatives (gradients)For f(x, y) = x² + 4y²: differentiate with respect to x (treating y as constant) to get ∂f/∂x = 2x. Differentiate with respect to y (treating x as constant) to get ∂f/∂y = 8y. So ∇f = ⟨2x, 8y⟩. For g(x, y) = x² + y²: similarly, ∂g/∂x = 2x and ∂g/∂y = 2y. So ∇g = ⟨2x, 2y⟩.
∇f = ⟨2x, 8y⟩, ∇g = ⟨2x, 2y⟩
3
Step 3 — Set up the Lagrange equationsSetting ∇f = λ∇g means each component must match. x-component: 2x = λ · 2x, i.e., 2x = 2λx. y-component: 8y = λ · 2y, i.e., 8y = 2λy. We also keep the constraint: x² + y² = 1.
4
Step 4 — Solve the systemFrom equation (i): 2x − 2λx = 0, so 2x(1 − λ) = 0. This means either x = 0 or λ = 1. Case A: If x = 0, the constraint gives 0 + y² = 1, so y = ±1. Case B: If λ = 1, then from equation (ii): 8y = 2(1)y → 8y − 2y = 0 → 6y = 0, so y = 0. The constraint gives x² = 1, so x = ±1.
Candidate points: (0, 1), (0, −1), (1, 0), (−1, 0)
5
Step 5 — Evaluate f at each candidatePlug each candidate into f(x, y) = x² + 4y²: f(0, 1) = 0 + 4(1)² = 4. f(0, −1) = 0 + 4(1)² = 4. f(1, 0) = 1² + 0 = 1. f(−1, 0) = (−1)² + 0 = 1. Compare: 4 > 1, so the maximum is 4 and the minimum is 1.
Maximum = 4 at (0, ±1); Minimum = 1 at (±1, 0)
6
Step 6 — Find and interpret λAt the maximum (0, 1): from equation (ii), 8(1) = 2λ(1) → λ = 4. At the minimum (1, 0): λ = 1 (from Case B). The multiplier λ = 4 at the maximum tells us that if the circle's radius squared increased from 1 to 1.01 (so the constraint changed from x² + y² = 1 to x² + y² = 1.01), the maximum value of f would increase by approximately 4 × 0.01 = 0.04. A larger λ means the optimum is more sensitive to how tight the constraint is.
λ = 4 at max; λ = 1 at min

Strengths, Limitations, & Comparisons

The Lagrange multiplier method is powerful, but like any tool, it has both strengths and limitations. Understanding when it works best—and when other approaches might be preferable—will help you choose the right strategy for each problem.

Comparing the Lagrange multiplier method's strengths and limitations
AspectStrengthsLimitations
GeneralityWorks for any differentiable objective and constraint functions, not just linear or simple ones.Requires both f and g to be differentiable—cannot handle constraints with sharp corners.
Geometric ClarityThe tangency condition ∇f = λ∇g provides deep visual intuition about why the method works.Does not directly tell you whether a candidate is a max, min, or neither—you must compare values.
ScalabilityExtends naturally to three or more variables and multiple constraints by adding more multipliers.The algebra can become very complex for systems with many variables and constraints.
InterpretationThe multiplier λ gives the sensitivity of the optimum to changes in the constraint—a free bonus.Only handles equality constraints (g = k). Inequality constraints (g ≤ k) need more advanced methods.
vs. SubstitutionAvoids messy algebraic substitution—especially helpful when g cannot be easily solved for one variable.For very simple constraints (like y = 3x), direct substitution is often faster.
🎯 WHEN TO USE LAGRANGE MULTIPLIERS
Use Lagrange multipliers when the constraint cannot be easily solved for one variable, or when you need the sensitivity information that λ provides. If the constraint is something simple like y = 2x + 1, direct substitution into f may be faster. Think of Lagrange multipliers as the power drill of optimization—not needed for every screw, but indispensable when the problem is complex.

Connections to Advanced Theory

The ideas behind Lagrange multipliers extend far beyond what you see in a first multivariable calculus course. Understanding where these concepts lead can give you a sense of how foundational this technique really is.

How constrained optimization scales from introductory to advanced
This CourseAdvanced Extension
One equality constraint: g(x, y) = kMultiple constraints: g₁ = k₁, g₂ = k₂, … each with its own multiplier λ₁, λ₂, …
λ interpreted as sensitivityIn economics, λ is the "shadow price"—the monetary value of relaxing a constraint by one unit
Equality constraints only (g = k)Karush-Kuhn-Tucker (KKT) conditions handle inequality constraints (g ≤ k), used in machine learning
Finite-dimensional (2–3 variables)Calculus of variations: optimizing functions of functions (e.g., finding the shortest path on a curved surface)
Analytical solution by handNumerical optimization algorithms (gradient descent with constraints) solve problems with millions of variables

The most exciting connection is to machine learning. When engineers train a neural network, they are essentially minimizing an error function subject to constraints like memory limits, fairness requirements, or regularization terms. The Lagrangian framework you learned here is the theoretical backbone of support vector machines, one of the most important algorithms in data science. Even if you never solve another Lagrange multiplier problem by hand, the intuition—that constraints reshape the optimization landscape and that the multiplier measures the cost of the constraint—will serve you in any quantitative field.

Practice Problems

PROBLEM 1CONCEPTUAL
In your own words, explain what it means geometrically when ∇f = λ∇g at a point on the constraint curve. Why does this condition identify potential maxima or minima of f along the constraint? (Hint: think about the hiking analogy from Section 2—what happens to your elevation when the trail runs along a contour line?)
PROBLEM 2BASIC CALCULATION
Find the maximum and minimum values of f(x, y) = x + y subject to the constraint x² + y² = 1. (Hint: compute ∇f and ∇g, set them proportional, then use x = y to substitute into the constraint.)
PROBLEM 3INTERMEDIATE
Minimize f(x, y) = x² + y² subject to the constraint 2x + 3y = 12. Also find the value of λ and explain what it tells you about how the minimum changes if the right-hand side of the constraint increases by 1.
PROBLEM 4APPLIED
A company manufactures two products. The revenue function is R(x, y) = 4x + 6y (in thousands of dollars), where x and y are the quantities produced. Production is limited by the resource constraint x² + y² = 50. How many of each product should the company produce to maximize revenue? What does λ represent in this business context?
PROBLEM 5CRITICAL THINKING
Consider maximizing f(x, y) = xy subject to the constraint x + y = 10. Solve this using both (a) the substitution method and (b) Lagrange multipliers. Compare the two approaches. Then explain why the Lagrange multiplier λ equals the value of each variable at the optimum. Finally, what happens to the optimal product xy if the constraint changes to x + y = 12? Estimate using λ, then verify by solving exactly.

Lesson Summary

Constrained optimization is the process of finding the maximum or minimum of an objective function f(x, y) while satisfying a constraint g(x, y) = k. This topic is part of college-level Multivariable Calculus and builds on single-variable calculus (derivatives) and algebra (systems of equations). The Lagrange multiplier method works by setting ∇f = λ∇g, where ∇f and ∇g are gradient vectors (pairs of partial derivatives). This captures the geometric condition that the level curves of f are tangent to the constraint curve at the optimum. Combined with the constraint equation itself, this produces a system of three equations you solve for x, y, and the multiplier λ.

The Lagrange multiplier λ is more than just a helper variable—it measures the sensitivity of the optimal value to changes in the constraint constant k. To determine whether candidate points are maxima or minima, evaluate f at each one and compare. This method generalizes to three or more variables and multiple constraints, and it forms the foundation of advanced topics in economics, engineering, and machine learning.

Varsity Tutors • Multivariable Calculus • Constrained Optimization — Optimize with constraints and interpret results