A mathematical and computational guide to constrained optimization, geometric gradient alignment, economic shadow prices, Karush-Kuhn-Tucker (KKT) inequality conditions, and numerical solvers in Python.
In operations research, portfolio allocation, statistical maximum likelihood estimation, and physics, maximizing or minimizing an objective function rarely happens in an unconstrained vacuum. Decisions are almost always bound by finite budgets, conservation laws, or physical capacities.
Developed by Joseph-Louis Lagrange, the Method of Lagrange Multipliers transforms a constrained optimization problem into an unconstrained saddle-point problem. Rather than solving explicitly for variables to eliminate constraints—which is often algebraically impossible for nonlinear systems—Lagrange multipliers introduce auxiliary dual variables that capture the exact sensitivity of the optimal objective to constraint perturbations.
1. Mathematical Formulation and Geometric Intuition
Consider optimizing a continuously differentiable objective function f(x) over x ∈ ℝn subject to m smooth equality constraints:
Maximize / Minimize f(x1, x2, …, xn)
Subject to gi(x1, x2, …, xn) = 0, for i = 1, 2, …, m
Why Gradients Must Align at the Optimum
Geometrically, at a constrained local extremum x*, any infinitesimal movement along the constraint manifold g(x) = 0 must yield zero first-order change in f(x). Because the gradient ∇g(x*) is orthogonal to the tangent plane of the constraint surface, the objective gradient ∇f(x*) cannot have a non-zero component parallel to that tangent plane—otherwise, moving along the constraint would strictly improve the objective.
Consequently, ∇f(x*) and ∇g(x*) must point along the exact same normal line, differing only by a scalar scaling factor λ (the Lagrange multiplier):
∇f(x*) = ∑i=1m λi ∇gi(x*)
The Lagrangian Function
We encapsulate both the objective and the constraints into a single scalar function, the Lagrangian ℒ(x, λ):
ℒ(x, λ) = f(x) − ∑i=1m λi gi(x)
Setting the gradient of ℒ with respect to both primal variables x and dual multipliers λ to zero yields a system of n + m stationary equations:
- Primal Stationarity: ∇xℒ = ∇f(x) − ∑i=1m λi ∇gi(x) = 0
- Primal Feasibility: ∇λℒ = −gi(x) = 0 ⇒ gi(x) = 0
2. Worked Analytical Example: Utility Maximization Under a Budget Constraint
Suppose a firm allocates capital across two production inputs x and y to maximize output modeled by a Cobb-Douglas production function f(x, y) = x0.5y0.5, subject to a linear budget constraint 2x + 8y = 160.
- Construct the Lagrangian:
ℒ(x, y, λ) = x0.5y0.5 − λ(2x + 8y − 160) - Compute First-Order Partial Derivatives:
- ∂ℒ/∂x = 0.5 x−0.5y0.5 − 2λ = 0 ⇒ λ = (y0.5) / (4x0.5)
- ∂ℒ/∂y = 0.5 x0.5y−0.5 − 8λ = 0 ⇒ λ = (x0.5) / (16y0.5)
- ∂ℒ/∂λ = −(2x + 8y − 160) = 0
- Equate λ Expressions to Find Optimal Ratio:
(y0.5) / (4x0.5) = (x0.5) / (16y0.5) ⇒ 16y = 4x ⇒ x = 4y - Substitute into the Budget Constraint:
2(4y) + 8y = 160 ⇒ 16y = 160 ⇒ y* = 10, x* = 40 - Evaluate Optimal Output and Multiplier:
f(40, 10) = √(400) = 20, and λ* = √10 / (4√40) = 1 / 8 = 0.125
Economic Interpretation (Shadow Price): By the Envelope Theorem, ∂f*/∂B = λ* = 0.125. Increasing the total budget from 160 to 161 units increases maximum achievable output by approximately 0.125 units.
3. Second-Order Conditions & Inequality Constraints (KKT)
Stationarity (∇ℒ = 0) identifies candidate critical points, which could be maxima, minima, or saddle points. Distinguishing them requires second-order checks, and real-world inequality bounds require extending Lagrange multipliers to the Karush-Kuhn-Tucker (KKT) framework.
| Optimization Regime | Mathematical Condition | Diagnostic Purpose |
|---|---|---|
| Constraint Qualification (LICQ) | Gradients {∇g1(x*), …, ∇gm(x*)} are linearly independent | Guarantees existence and uniqueness of finite multipliers λi |
| Bordered Hessian (HB) | Evaluates definiteness of ∇xx2ℒ restricted to the tangent subspace ∇g(x*)d = 0 | Verifies whether critical point is a strict constrained local maximum or minimum |
| KKT Complementary Slackness | μj hj(x*) = 0 with μj ≥ 0 for inequality hj(x) ≤ 0 | Forces μj = 0 when a constraint is inactive (slack) and μj > 0 when binding |
4. Numerical Implementation in Python (SciPy)
For high-dimensional nonlinear problems where closed-form algebraic elimination is intractable, Sequential Least Squares Programming (SLSQP) and Trust-Region Constrained algorithms (trust-constr) in scipy.optimize solve the primal-dual system simultaneously and return the exact Lagrange multipliers.
import numpy as np
from scipy.optimize import minimize
# Minimize negative Cobb-Douglas output: -x^0.5 * y^0.5
def objective(vars):
x, y = vars
return -np.sqrt(x * y)
# Equality constraint: 2x + 8y - 160 = 0
def budget_constraint(vars):
x, y = vars
return 2.0 * x + 8.0 * y - 160.0
# Initial guess and positivity bounds
x0 = np.array([10.0, 10.0])
bounds = [(1e-6, None), (1e-6, None)]
# Solve using trust-constr to inspect both primal solution and Lagrange multiplier
result = minimize(
objective,
x0,
method="trust-constr",
bounds=bounds,
constraints={"type": "eq", "fun": budget_constraint},
)
x_opt, y_opt = result.x
# Multiplier sign reflects minimization of -f(x, y)
lambda_shadow_price = -result.v[0][0]
print(f"Optimal Allocation: x* = {x_opt:.4f}, y* = {y_opt:.4f}")
print(f"Maximum Output: f* = {-result.fun:.4f}")
print(f"Shadow Price (λ*): {lambda_shadow_price:.4f}")
5. Key Modeling Takeaways
- Dimensionality Trade-Off: Lagrange multipliers replace variable substitution with an expanded system of n + m equations, preserving symmetry across variables and avoiding messy algebraic radicals.
- Dual Sensitivity Analysis: Each multiplier λi quantifies the marginal rate of change in the optimal objective per unit relaxation of constraint i, providing immediate economic or physical sensitivity metrics without re-solving the model.
- Always Verify Constraint Qualification: If constraint gradients vanish or become collinear at an optimum (violating LICQ), standard Lagrange multipliers can fail to exist even at a valid constrained extremum.
No comments:
Post a Comment