Optimization

Lagrange Multipliers and Constrained Optimization

Lagrange multipliers turn a constrained optimum into a normal-vector alignment condition and interpret the multiplier as local constraint sensitivity.

status: reviewimportance: criticaldifficulty 4/5math: graduateread: 17mlive demo

Concept Structure

Lagrange Multipliers and Constrained Optimization

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

2prerequisites
2next concepts
3related links

Learner Contract

What this page should let you do.

You are here becauseLagrange multipliers turn a constrained optimum into a normal-vector alignment condition and interpret the multiplier as local constraint sensitivity.

This Optimization concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

By the end4/4 sections ready | runnable code expected | live demo

Explain the mechanism, trace the main notation, and test one prediction in the live demo.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Test the linkManipulate one control and predict the visible change.Then continue to Duality and KKT Conditions (review)

Claim/source review status

Substantive review recorded

1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.
Claims1/1 reviewed
Sources3 cited
Codeattached
Demolive
Reviewed2026-07-02
Updatedpage 2026-07-02

Learning item flow

4/4 sections readyAsk about thisResearch room
ConceptLagrange Multipliers and Constrained OptimizationOptimization
3 sources attachedLocal snapshot ready
concept:optimization/lagrange-multipliers-constrained-optimization
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

A constraint changes what "downhill" means.

If you can move anywhere, minimizing a smooth function means looking for a point where the gradient is zero. But on a constraint, most directions are illegal. A point can still have a nonzero objective gradient and be optimal, because the gradient may point straight out of the feasible surface instead of along it.

Think about minimizing distance to a target while staying on a circle. The unconstrained best point is the target itself. If the target is outside the circle, you cannot go there. The constrained best point is where the circle gets closest to the target.

At that point, the objective gradient does not run along the circle. It points normal to the circle. Every legal first-order move is tangent, and tangent motion no longer improves the objective. That is the core Lagrange multiplier picture:

  • the constraint gradient h(x)\nabla h(x) points normal to the feasible surface h(x)=0h(x)=0;
  • the objective gradient f(x)\nabla f(x) must have no tangent component at a constrained optimum;
  • therefore f(x)\nabla f(x^\star) is a scalar multiple of h(x)\nabla h(x^\star).

The multiplier is not just algebraic decoration. In a well-behaved problem it also tells you sensitivity: if you loosen or tighten the constraint a little, the optimal value changes at a rate controlled by the multiplier.

This page deliberately stops before full inequality KKT theory. The next page can introduce active constraints, complementary slackness, and dual certificates. First we need the simpler skill: see the normal-vector alignment and read the multiplier as "how much the constraint is biting."

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Start with a smooth equality-constrained minimization problem:

minxf(x)subject toh(x)=0.\min_x f(x) \quad\text{subject to}\quad h(x)=0.

The feasible directions vv at a smooth point satisfy the first-order constraint condition

h(x)v=0.\nabla h(x)^\top v = 0.

So feasible directions are tangent to the level set of hh. If xx^\star is a constrained local minimizer, then no feasible first-order direction should reduce the objective:

f(x)v=0for every tangent direction v.\nabla f(x^\star)^\top v = 0 \quad\text{for every tangent direction }v.

That means f(x)\nabla f(x^\star) is orthogonal to the tangent space. For one equality constraint, the normal space is spanned by h(x)\nabla h(x^\star), so there is a scalar λ\lambda^\star such that

f(x)+λh(x)=0.\nabla f(x^\star) + \lambda^\star \nabla h(x^\star)=0.

Equivalently, define the Lagrangian

L(x,λ)=f(x)+λh(x).\mathcal{L}(x,\lambda)=f(x)+\lambda h(x).

The first-order equations are

xL(x,λ)=0,h(x)=0.\nabla_x\mathcal{L}(x^\star,\lambda^\star)=0, \qquad h(x^\star)=0.

Now use the toy problem from the demo. Let cR2c\in\mathbb{R}^2 be a target point outside the unit circle and solve

minx12xc22subject toh(x)=xx1=0.\min_x \frac12\|x-c\|_2^2 \quad\text{subject to}\quad h(x)=x^\top x-1=0.

Here

f(x)=xc,h(x)=2x.\nabla f(x)=x-c, \qquad \nabla h(x)=2x.

The Lagrange condition is

xc+2λx=0.x^\star-c+2\lambda^\star x^\star=0.

Because xx^\star lies on the unit circle, the closest feasible point is the normalized target direction:

x=cc2.x^\star=\frac{c}{\|c\|_2}.

Substitute this into the stationarity equation:

λ=c212.\lambda^\star=\frac{\|c\|_2-1}{2}.

For the perturbed constraint xxρ=0x^\top x-\rho=0, the optimal value is

p(ρ)=12(c2ρ)2.p^\star(\rho)=\frac12(\|c\|_2-\sqrt{\rho})^2.

At ρ=1\rho=1,

dpdρ=λ.\frac{d p^\star}{d\rho}=-\lambda^\star.

So if λ\lambda^\star is large and positive, loosening the squared-radius constraint decreases the best achievable objective value quickly. That is the sensitivity interpretation the demo asks you to inspect.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

c = np.array([1.8, 1.1])          # unconstrained target
rho = 1.0                         # circle: x^T x = rho
r = np.sqrt(rho)

x_star = r * c / np.linalg.norm(c)
grad_f = x_star - c
grad_h = 2.0 * x_star
lambda_star = -grad_f @ grad_h / (grad_h @ grad_h)

p_star = 0.5 * np.linalg.norm(x_star - c) ** 2
rho_step = 1e-4
r2 = np.sqrt(rho + rho_step)
x2 = r2 * c / np.linalg.norm(c)
p2 = 0.5 * np.linalg.norm(x2 - c) ** 2
finite_diff = (p2 - p_star) / rho_step

print("x_star:", np.round(x_star, 3))
print("grad_f:", np.round(grad_f, 3))
print("grad_h:", np.round(grad_h, 3))
print("lambda:", round(lambda_star, 3))
print("sensitivity dp*/d rho:", round(finite_diff, 3))
print("-lambda:", round(-lambda_star, 3))

The witness computes the same object as the live lab. The multiplier comes from projecting f\nabla f onto the constraint normal. The finite difference checks the sensitivity claim by slightly loosening the squared-radius constraint.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

The lab asks for the vector relation before revealing the arrows and ledger. Predict first: at the constrained minimizer, should the objective gradient be tangent to the circle, normal to the circle, or should the point simply equal the unconstrained target?

Live Concept Demo

Explore Lagrange Multipliers and Constrained Optimization

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 4/5graduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Lagrange Multipliers and Constrained Optimization should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Lagrange multipliers turn a constrained optimum into a normal-vector alignment condition and interpret the multiplier as local constraint sensitivity.

Prediction open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Lagrange Multipliers and Constrained Optimization should make visible.

Visual Inquiry

Make the image answer a mathematical question

Lagrange multipliers turn a constrained optimum into a normal-vector alignment condition and interpret the multiplier as local constraint sensitivity.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Lagrange Multipliers and Constrained Optimization easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

book · 2020Mathematics for Machine LearningDeisenroth, Faisal, and Ong

Supports constrained optimization, Lagrange multipliers, equality-constraint multiplier freedom, duality setup, and the PCA eigenvector example.

Open source
book · 2004Convex OptimizationBoyd and Vandenberghe

Supports the Lagrangian, Lagrange multiplier optimality conditions, KKT stationarity, and multiplier sensitivity interpretation.

Open source
course-notes · 2009CS229 Section Notes: Convex Optimization OverviewChuong B. Do, Stanford CS229

Supports Lagrangian dual variables as constraint costs, weak/strong duality intuition, KKT conditions, and the SVM support-vector connection.

Open source

Claim Review

Lagrange multipliers turn a constrained optimum into a normal-vector alignment condition and interpret the multiplier as local constraint sensitivity.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources3 references

deisenroth-2020-mml-lagrange, boyd-2004-convex-optimization-lagrange, cs229-cvxopt2-lagrange-duality

Local checks4 local checks

Use equations, runnable code, and demos to check whether the source support is operational.

Substantively reviewedFor a smooth equality-constrained optimum, the objective gradient aligns with the constraint normal, and under well-behaved perturbations the multiplier gives local optimal-value sensitivity.Claim metadata: source checked

The sources support constrained optimization as the right setting, the construction of a Lagrangian with multiplier variables, the stationarity equation, the equality multiplier being unconstrained, and the sensitivity reading of optimal multipliers.

Sources: Mathematics for Machine Learning, Convex Optimization, CS229 Section Notes: Convex Optimization OverviewThis page teaches a smooth equality-constrained toy and only previews inequality constraints, duality, and KKT. It does not certify second-order sufficiency, constraint qualification edge cases, nonsmooth constraints, numerical solver behavior, or SVM dual derivations.A bounded review summary is present; still check caveats and exact reference scope.

Checked MML chapter 7 for constrained optimization, Lagrange multipliers, equality-constraint multiplier treatment, and PCA as constrained optimization; Boyd/Vandenberghe chapters 4-5 for equality-constrained optimality, Lagrangian multiplier vectors, KKT stationarity, and sensitivity; and Stanford CS229 convex optimization notes for Lagrangian dual variables, KKT stationarity, active constraints, and SVM motivation. GPT Pro publication critique remains pending because 127.0.0.1:51672 refused connection.

Reviewer: codex-local-source-review; reviewed 2026-07-02

Practice Loop

Try the idea before it explains itself

Lagrange multipliers turn a constrained optimum into a normal-vector alignment condition and interpret the multiplier as local constraint sensitivity.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Lagrange Multipliers and Constrained Optimization.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Grounded research drawerClose
ConceptLagrange Multipliers and Constrained OptimizationOptimization

Research Room

Attach the question to a claim, equation, code, or demo

Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptOptimization

Lagrange Multipliers and Constrained Optimization

Attached question

What is the smallest example that makes Lagrange Multipliers and Constrained Optimization click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays in this browser, attached to the selected learning item.

No local draft saved.
Evidence to inspect
  • References to inspect: attached references on this page.
  • Definition, prerequisite, and contrast concept links
  • The equation or runnable code that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Lagrange Multipliers and Constrained Optimization Selected item key: recorded for copy. Context: Optimization Page anchor: recorded for copy. Open question: What is the smallest example that makes Lagrange Multipliers and Constrained Optimization click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

View it in context
concept/concept-notebook/optimization/lagrange-multipliers-constrained-optimization concept:optimization/lagrange-multipliers-constrained-optimization