Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

 Open In Colab

In previous sections, we focused on unconstrained minimization: finding x∈Rn\mathbf{x} \in \mathbb{R}^n that minimizes an objective function f(x)f(\mathbf{x}).

Many practical engineering problems require finding an optimum that satisfies physical restrictions or conservation laws expressed as equality constraints:

min⁡xf(x)subject tog(x)=0\min_{\mathbf{x}} f(\mathbf{x}) \quad \text{subject to} \quad \mathbf{g}(\mathbf{x}) = \mathbf{0}

Here, g(x)=0\mathbf{g}(\mathbf{x}) = \mathbf{0} represents mm simultaneous scalar constraints (m<nm < n). For example, constraining a 2D trajectory to the unit circle:

x2+y2=1g(x,y)=x2+y2−1=0\begin{aligned} x^2 + y^2 &= 1 \\ g(x, y) = x^2 + y^2 - 1 &= 0 \end{aligned}

Penalty Method

A straightforward heuristic for enforcing constraints is to augment the objective function with a penalty term proportional to the constraint violation:

min⁡xf(x)=f(x)+λ∥g(x)∥2\min_{\mathbf{x}} f(\mathbf{x}) = f(\mathbf{x}) + \lambda \|\mathbf{g}(\mathbf{x})\|^2

where λ>0\lambda > 0 is a penalty parameter. When the constraint is violated (g(x)≠0\mathbf{g}(\mathbf{x}) \ne \mathbf{0}), the penalty increases the effective cost.

While intuitive, penalty methods face severe practical challenges:

  • Too small λ\lambda: The optimizer drifts away from the constraint surface, yielding infeasible solutions.

  • Too large λ\lambda: The penalty introduces steep, narrow canyon walls into the objective landscape, resulting in an ill-conditioned Hessian (H∼λ\mathbf{H} \sim \lambda) that stalls gradient-based and Newton solvers.

Sequential unconstrained minimization techniques (SUMT) adjust λ\lambda iteratively, but balancing feasibility against numerical conditioning remains challenging.

Method of Undetermined Lagrange Multipliers

At the constrained optimum, the constraint is satisfied exactly (g(x∗)=0\mathbf{g}(\mathbf{x}^*) = \mathbf{0}). Instead of choosing an arbitrary scalar penalty λ\lambda, we treat the multiplier λ\boldsymbol{\lambda} as an unknown variable to be determined simultaneously with x\mathbf{x}.

We formulate the Lagrangian function:

L(x,λ)=f(x)+λTg(x)\mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}) = f(\mathbf{x}) + \boldsymbol{\lambda}^T \mathbf{g}(\mathbf{x})

The necessary condition for a constrained stationary point is that the gradient of the Lagrangian with respect to both x\mathbf{x} and λ\boldsymbol{\lambda} vanishes:

∇L(x,λ)=0\nabla \mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}) = \mathbf{0}

Differentiating with respect to the multipliers λ\boldsymbol{\lambda} recovers the constraint equations:

∂L∂λ=g(x)=0\frac{\partial \mathcal{L}}{\partial \boldsymbol{\lambda}} = \mathbf{g}(\mathbf{x}) = \mathbf{0}

Remarkably, the Lagrangian formulation converts a constrained optimization problem into an unconstrained problem ∇x,λL=0\nabla_{\mathbf{x,\lambda}} \mathcal{L} = \mathbf{0} which implies our normal optimization methods apply (or one of them will anyway)!

Geometric Interpretation of the Optimality Condition

Differentiating the Lagrangian with respect to x\mathbf{x} yields:

∂L∂x=∇f(x)+∑i=1mλi∇gi(x)=0  ⟹  ∇f(x)=−∑i=1mλi∇gi(x)\frac{\partial \mathcal{L}}{\partial \mathbf{x}} = \nabla f(\mathbf{x}) + \sum_{i=1}^m \lambda_i \nabla g_i(\mathbf{x}) = \mathbf{0} \implies \nabla f(\mathbf{x}) = -\sum_{i=1}^m \lambda_i \nabla g_i(\mathbf{x})

Along the constraint curve g(x)=0\mathbf{g}(\mathbf{x}) = \mathbf{0}, the gradient of the objective function ∇f\nabla f must be parallel (or anti-parallel) to the normal of the constraint curve ∇g\nabla g. If ∇f\nabla f had any non-zero component tangential to the constraint curve, we could decrease f(x)f(\mathbf{x}) further by moving along that curve without violating the constraint!

Hiking Analogy: Imagine walking along a narrow mountain trail defined by g(x,y)=0g(x, y) = 0 while the mountain height is f(x,y)f(x, y). To find the lowest point on the trail, you hike downhill along the path. At the lowest path elevation, the ground slopes perpendicularly away from the trail (∇f∥∇g\nabla f \parallel \nabla g). To prevent falling down the slope, you must push against the slope with constraint force λ\lambda.

Quadratic Programming with Linear Equality Constraints

If we blindly apply Lagrange multipliers, our methods will likely fail. To understand why, consider a quadratic objective and linear constraints (i.e.: a 2nd order Taylor expansion). The Lagrangian is quadratic:

f(x)=12xTHx+cTx,g(x)=Ax−b=0f(\mathbf{x}) = \frac{1}{2} \mathbf{x}^T \mathbf{H} \mathbf{x} + \mathbf{c}^T \mathbf{x}, \quad \mathbf{g}(\mathbf{x}) = \mathbf{A} \mathbf{x} - \mathbf{b} = \mathbf{0}
L=12xTHx+cTx+λ(Ax−b)\mathcal{L} = \frac{1}{2} \mathbf{x}^T \mathbf{H} \mathbf{x} + \mathbf{c}^T \mathbf{x} +\boldsymbol{\lambda} (\mathbf{A} \mathbf{x} - \mathbf{b})

The stationary conditions ∇xL=0\nabla_{\mathbf{x}} \mathcal{L} = \mathbf{0} and ∇λL=0\nabla_{\boldsymbol{\lambda}} \mathcal{L} = \mathbf{0} become:

Hx+c+ATλ=0Ax−b=0\begin{aligned} \mathbf{H} \mathbf{x} + \mathbf{c} + \mathbf{A}^T \boldsymbol{\lambda} &= \mathbf{0} \\ \mathbf{A} \mathbf{x} - \mathbf{b} &= \mathbf{0} \end{aligned}

Writing this as a block system yields the symmetric Karush-Kuhn-Tucker (KKT) linear system: $$\begin{bmatrix} \mathbf{H} & \mathbf{A}^T \ \mathbf{A} & \mathbf{0} \end{bmatrix}

[xλ]\begin{bmatrix} \mathbf{x} \\ \boldsymbol{\lambda} \end{bmatrix}

=

[−cb]\begin{bmatrix} -\mathbf{c} \\ \mathbf{b} \end{bmatrix}

Remarkably, solving a linearly constrained quadratic program reduces to solving a single square linear system!

Example: Quadratic KKT System

Minimize the objective f(x,y,z)=xy+yzf(x, y, z) = xy + yz subject to two linear constraints:

x+2y=6andx−3z=0x + 2y = 6 \quad \text{and} \quad x - 3z = 0

Here x=[x,y,z]T\mathbf{x} = [x, y, z]^T, c=[0,0,0]T\mathbf{c} = [0, 0, 0]^T, and:

H=[010101010],A=[12010−3],b=[60]\mathbf{H} = \begin{bmatrix} 0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0 \end{bmatrix}, \quad \mathbf{A} = \begin{bmatrix} 1 & 2 & 0 \\ 1 & 0 & -3 \end{bmatrix}, \quad \mathbf{b} = \begin{bmatrix} 6 \\ 0 \end{bmatrix}

Assembling the 5×55 \times 5 KKT matrix K=[HATA0]\mathbf{K} = \begin{bmatrix} \mathbf{H} & \mathbf{A}^T \\ \mathbf{A} & \mathbf{0} \end{bmatrix}, we solve K[xλ]=[−cb]\mathbf{K} \begin{bmatrix} \mathbf{x} \\ \boldsymbol{\lambda} \end{bmatrix} = \begin{bmatrix} -\mathbf{c} \\ \mathbf{b} \end{bmatrix}.

Saddle-Point Structure of the KKT Matrix

Inspecting the eigenvalues of the KKT matrix reveals a fundamental property of constrained optimization.

Because the eigenvalues have opposite signs (both positive and negative), the KKT system is indefinite. The constrained optimum is not a local minimum of L(x,λ)\mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}), but a saddle point (a minimum with respect to x\mathbf{x}, and a maximum with respect to λ\boldsymbol{\lambda}).

Standard unconstrained descent methods fail when applied naively to the Lagrangian. However, the block structure of the KKT matrix makes it directly amenable to block elimination and specialized constrained solvers.

Meaning of the Lagrange Multipliers

Lagrange multipliers λi\lambda_i represent the sensitivity (marginal rate of change) of the optimal objective value f∗f^* with respect to relaxing the ii-th constraint:

λi∗=−∂f∗∂bi\lambda_i^* = -\frac{\partial f^*}{\partial b_i}

Depending on the domain, λi∗\lambda_i^* carries profound physical and economic meaning:

  • Structural & Mechanical Engineering: λi\lambda_i corresponds to the constraint reaction force (or internal stress) required to maintain the boundary condition gi(x)=0g_i(\mathbf{x}) = 0.

  • Economics & Operations Research: λi\lambda_i is the shadow price or marginal cost of relaxing a resource limit by one unit.

  • Thermodynamics & Statistical Physics: Multipliers represent conjugate thermodynamic potentials (e.g., temperature β=1/kBT\beta = 1/k_B T enforcing average energy conservation, chemical potential μ\mu enforcing particle conservation).

General Constrained Optimization

For nonlinear objective functions subject to nonlinear equality or inequality constraints:

min⁡xf(x)subject tog(x)=0,h(x)≤0\min_{\mathbf{x}} f(\mathbf{x}) \quad \text{subject to} \quad \mathbf{g}(\mathbf{x}) = \mathbf{0}, \quad \mathbf{h}(\mathbf{x}) \le \mathbf{0}

Modern numerical solvers employ two primary families of algorithms:

  1. Sequential Quadratic Programming (SQP): Solves a sequence of quadratic programming subproblems, iteratively approximating the Hessian of the Lagrangian and linearizing constraints (e.g., SLSQP in SciPy).

  2. Interior-Point (Barrier) / Trust-Region Methods: Traverses the interior of the feasible region using a barrier function for inequalities while enforcing equality constraints via trust-region steps (e.g., trust-constr in SciPy).

Example: Minimizing x4+y4x^4 + y^4 on the Unit Circle

Consider minimizing the quartic objective f(x,y)=x4+y4f(x, y) = x^4 + y^4 subject to the equality constraint g(x,y)=x2+y2−1=0g(x, y) = x^2 + y^2 - 1 = 0 (the unit circle).

The unconstrained minimum is at the origin (0,0)(0, 0), where f(0,0)=0f(0, 0) = 0. On the unit circle x2+y2=1x^2 + y^2 = 1, the function achieves four symmetric minima at (±1/2,±1/2)≈(±0.707,±0.707)(\pm 1/\sqrt{2}, \pm 1/\sqrt{2}) \approx (\pm 0.707, \pm 0.707) with f∗=0.5f^* = 0.5.

We solve this using SciPy’s Sequential Least Squares Programming (SLSQP) optimizer and visualize the surface, constraint ring, and optimum.

Example: Constraining an Indefinite Saddle System

Next, consider the hyperbolic saddle objective f(x,y)=x2−6xy+y2f(x, y) = x^2 - 6xy + y^2 subject to the unit circle constraint x2+y2=1x^2 + y^2 = 1.

In unconstrained space, the origin (0,0)(0, 0) is a saddle point where the Hessian has eigenvalues of opposite signs (λ1=8,λ2=−4\lambda_1 = 8, \lambda_2 = -4). When restricted to the unit circle, the objective attains constrained minima at (±1/2,±1/2)(\pm 1/\sqrt{2}, \pm 1/\sqrt{2}) with f∗=−2f^* = -2.

We solve this using SciPy’s trust-region constrained optimizer (trust-constr).

Example: Inequality Constraints on the Unit Disk

Finally, consider minimizing f(x,y)=sin⁡(x)cos⁡(y)+x2+y2f(x, y) = \sin(x)\cos(y) + x^2 + y^2 subject to an inequality constraint:

x2+y2≤1  ⟺  x2+y2−1≤0x^2 + y^2 \le 1 \iff x^2 + y^2 - 1 \le 0

The feasible region is the closed unit disk. When optimizing with inequalities, the constraint may be:

  • Active: The unconstrained minimum lies outside the disk; the constrained optimum sits on the boundary x2+y2=1x^2 + y^2 = 1.

  • Inactive: The unconstrained minimum lies strictly inside the disk; the multiplier λ=0\lambda = 0.

We formulate this using SciPy’s NonlinearConstraint(fun, -np.inf, 0) with trust-constr.