Quadratic programming over a polygon
The question
When your target lies outside a triangle with a cap, where is the best point you can actually choose?
- 1 SeePlace a point and choose its constraints.
- 2 TryChange the curvature and compare the answers.
- 3 ProveBuild a certificate of optimality.
- 4 ApplySolve problems with edges and corners.
Before you start · 3 quick checks on inequalities, dot products, and curvature, about 3 min
Two ideas before you start
2 ideasThe constraints mark out the polygon
The feasible triangle lies above and to the right of the axes and below a diagonal line.
Switch points to compare them with the cap.
A point is feasible when it meets all the inequalities, including equality at a boundary. An inequality is active at a point when it holds with equality there.
Exact definition
Write each constraint as \(a_i^\mathsf{T}z \le b_i\), where \(z=(x,y)\) and \(a_i\) is a nonzero outward normal to its boundary line. The feasible set is the intersection of these closed half-planes. If this intersection is bounded and has interior, it is a filled convex polygon.
The slack at a point \(z\) is \(b_i-a_i^\mathsf{T}z\). Feasibility means all slacks are nonnegative. An active constraint has zero slack. The lesson on separating hyperplanes works with the same half-planes and their normals.
Each contour has one objective value
A contour around the origin narrows horizontally when horizontal errors receive a higher weight.
Each curve shows all points with the same objective value. Giving one coordinate a higher penalty makes the curve narrower in that direction.
Exact definition
A quadratic program minimizes a quadratic objective under linear constraints. Let \(H\) be a real symmetric matrix, \(c\) a vector, and \(r\) a constant. The objective is
\[f(z)=\tfrac12 z^\mathsf{T}Hz+c^\mathsf{T}z+r.\]The factor \(\tfrac12\) makes the gradient \(Hz+c\) and the Hessian (the matrix of second derivatives) \(H\). Positive semidefinite means \(d^\mathsf{T}Hd\ge0\) for all vectors \(d\). Positive definite means \(d^\mathsf{T}Hd\gt0\) for every nonzero \(d\). See positive semidefinite matrices for the directional quadratic form.
Fine print about the bowl
The interactive examples use a diagonal Hessian with positive entries. Think of each term as a penalty for missing a coordinate of a target. The target minimizes the objective over the whole plane, since both squared misses vanish there. The feasible polygon is independent of the target and the penalties.
A positive definite Hessian can also include a cross term, which can rotate the ellipses. If the Hessian is positive semidefinite and singular, it has a direction of zero curvature. The full objective is flat along that direction when its linear component there vanishes.
Place the minimizer and pick its active constraints
- Move the point with the coordinate sliders or enter its coordinates in the boxes. Smaller contours enclose lower objective values.
- Select the constraints you think are active at the optimum. Press Check my point and constraints to submit both.
How the game checks the choice
The Karush–Kuhn–Tucker (KKT) conditions use nonnegative multipliers here. Write each bound as \(a_i^\mathsf{T}z \le b_i\). Stationarity asks the weighted sum of the outward normals to cancel the objective gradient. The page sets unselected multipliers to zero. For one selected constraint it projects the negative gradient onto that normal and reports any residual. For two selected constraints the normals are independent, so solving the two coordinate equations gives the proposed multipliers. It then checks every sign and every slack–multiplier product.
The true optimum is computed separately. The page tests the target for feasibility, minimizes the quadratic along each closed edge, and compares those candidates. On an edge, a stationary point of the resulting one-variable function wins when it is on the segment. When the stationary point is beyond an endpoint, that endpoint wins on the edge. Each closed edge includes its endpoints, so the vertices are among the candidates without a separate rule.
The same cap with different penalties
Keep the feasible triangle and target fixed while you change the price of missing the horizontal coordinate.
The explorer opens after you check your prediction.
- Change the horizontal penalty. The target and triangle stay put while the minimizer moves.
- Use the two coordinate misses in the tiles to reach each goal.
Goals
Why compare weighted misses?
Let the target be \((u,v)\), the weights be \(\alpha,\beta\), and the cap be \(x+y\le B\). On the sloped edge the misses \(u-x\) and \(v-y\) add to \(u+v-B\). Moving along that edge trades one miss for the other. At an optimum in the interior of the edge, differentiating along the edge gives \(\alpha(u-x)=\beta(v-y)\). If the edge minimizer falls outside the segment, check the endpoint instead.
Here both misses are positive throughout the explorer. The product of a weight and its miss is the same for the two coordinates. The multiplier on the cap is twice that product because the objective uses the full squares.
Certify the point over the whole region
Let \(f\) be the quadratic from the setup, with \(H\) symmetric positive definite. Let \(p\) be feasible for a finite collection of linear inequalities \(a_i^\mathsf{T}z\le b_i\). Suppose the real multipliers \(\lambda_i\) satisfy the following conditions.
- Dual feasibility means \(\lambda_i\ge0\) for each \(i\).
- Stationarity means \(\nabla f(p)+\sum_i\lambda_i a_i=0\).
- Complementary slackness means \(\lambda_i(b_i-a_i^\mathsf{T}p)=0\) for each \(i\).
Then \(p\) is the unique global minimizer on the feasible set. The sums run over the listed inequalities. Fix another feasible point \(q\ne p\), if there is one, and write \(d=q-p\). Build the comparison with \(f(p)\) for this \(q\).
What changes with zero curvature?
With \(H\) positive semidefinite, the same certificate gives \(f(q)\ge f(p)\). A tie requires both zero linear contribution along \(q-p\) and zero quadratic contribution there. Positive definiteness ruled out the second equality for distinct points. A singular Hessian alone does not determine whether there is a tie. The feasible directions and the linear term matter too.
Geometrically, when \(\nabla f(p)\ne0\), the line through \(p\) perpendicular to the gradient supports the feasible polygon. The feasible points all lie in the closed half-plane toward the gradient. At a corner the negative gradient can be a nonnegative combination of the two outward normals there. A tight constraint can have a zero coefficient in that combination. See inequality constraints and the KKT conditions for the wider framework.
Solve and certify
Enter a decimal or a fraction. Each problem gives its grading precision and has hints and a worked solution.
Further reading
- S. Boyd and L. Vandenberghe, Convex Optimization, “Quadratic optimization problems.”
- J. Nocedal and S. J. Wright, Numerical Optimization, “Quadratic Programming.”