Local Extrema and Optimization of Functions of Two Variables
A function f(x, y) can have a local extremum only at a critical point, where fx = fy = 0; the second derivative test with D = fxxfyy − fxy2 classifies it: D > 0 with fxx > 0 is a local minimum, D > 0 with fxx < 0 a local maximum, and D < 0 a saddle point. In brief: f(x, y) = x3 − 3x + y2 has the critical points (1, 0) and (−1, 0); at (1, 0), D = 12 > 0 and fxx = 6 > 0, a local minimum with the value −2; at (−1, 0), D = −12 < 0, a saddle point.
Finding the best value of a quantity that depends on two variables is one of the main applications of calculus. This guide explains critical points, the second derivative test and its connection with the Hessian matrix, absolute extrema on closed regions, constrained optimization with Lagrange multipliers and a practical box problem, with worked examples and a table.
What are critical points?
If f has a local extremum at an interior point (a, b) where the partial derivatives exist, then fx(a, b) = 0 and fy(a, b) = 0, because along each coordinate line the function of one variable has an extremum (Fermat’s rule). Points where both partials vanish (or where one does not exist) are critical points. A critical point need not be an extremum: a saddle point is a critical point that is a minimum in one direction and a maximum in another.
How does the second derivative test work?
At a critical point (a, b), compute D = fxxfyy − (fxy)2, the determinant of the Hessian matrix [[fxx, fxy], [fxy, fyy]]. Then:
- D > 0 and fxx > 0: a local minimum;
- D > 0 and fxx < 0: a local maximum;
- D < 0: a saddle point;
- D = 0: the test is inconclusive.
The reason is that near a critical point f behaves like its second-order Taylor expansion, a quadratic form with the Hessian matrix, whose definiteness decides the type: D > 0 with fxx > 0 means positive definite.
Example 1: a bowl
f = x2 + y2 − 2x − 4y + 5. fx = 2x − 2 = 0 and fy = 2y − 4 = 0 give (1, 2). fxx = 2, fyy = 2, fxy = 0, so D = 4 > 0 and fxx > 0: a minimum, f(1, 2) = 1 + 4 − 2 − 8 + 5 = 0. Indeed f = (x − 1)2 + (y − 2)2.
Example 2: a minimum and a saddle
f = x3 − 3x + y2. fx = 3x2 − 3 = 0 gives x = ±1, and fy = 2y = 0 gives y = 0. fxx = 6x, fyy = 2, fxy = 0. At (1, 0): D = 12 > 0, fxx = 6 > 0, a local minimum, f = −2. At (−1, 0): D = −12 < 0, a saddle point (f = 2 there, but the function rises in the y direction and falls in the x direction).
Example 3: two critical points
f = x3 + y3 − 3xy. fx = 3x2 − 3y = 0 and fy = 3y2 − 3x = 0, so y = x2 and x = y2, giving x = x4, so x = 0 or x = 1: the points (0, 0) and (1, 1). fxx = 6x, fyy = 6y, fxy = −3. At (0, 0): D = −9 < 0, a saddle. At (1, 1): D = 36 − 9 = 27 > 0 and fxx = 6 > 0, a local minimum with f = 1 + 1 − 3 = −1.
Example 4: when D = 0
f = x4 + y4 has the critical point (0, 0) with D = 0, and it is a minimum. But f = x3 + y3 also has D = 0 at the origin, where there is no extremum. The test is inconclusive and one must examine the function directly.
How do you find absolute extrema on a closed region?
A continuous function on a closed bounded region attains its maximum and minimum. Find the critical points in the interior, find the extreme values on the boundary, and compare all values.
Example 5: a square
f = x2 + y2 − 2x − 2y + 4 on the square [0, 2] × [0, 2]. Interior: fx = 2x − 2 = 0 and fy = 2y − 2 = 0 give (1, 1) with f = 2. Edge y = 0: x2 − 2x + 4, minimum 3 at x = 1, and the ends give 4. By symmetry the other edges are similar. The corners all have f = 4. So the absolute minimum is 2 at (1, 1), and the absolute maximum is 4 at the four corners.
How do you optimize under a constraint?
To optimize f(x, y) subject to g(x, y) = 0, either solve the constraint for one variable and substitute, or use Lagrange multipliers: at a constrained extremum ∇f = λ∇g, that is fx = λgx, fy = λgy, together with g = 0. Geometrically, the level curve of f is tangent to the constraint curve.
Example 6: the largest product
Maximize xy subject to x + y = 10. By substitution: y = 10 − x gives 10x − x2, with the maximum at x = 5. With multipliers: y = λ and x = λ, so x = y = 5, and the product is 25.
Example 7: a point nearest to the origin
Minimize x2 + y2 subject to x + 2y = 5. Then 2x = λ and 2y = 2λ, so y = 2x; the constraint gives x + 4x = 5, x = 1, y = 2. The minimal squared distance is 5, the distance is √5, consistent with the distance from a point to a line formula 5/√5 = √5.
Which applications are typical?
Example 8: an open box
An open-top box with the volume 32 m3 should use the least material. With the base x × y and the height h = 32/(xy), the area is S = xy + 2h(x + y) = xy + 64/y + 64/x. Sx = y − 64/x2 = 0 and Sy = x − 64/y2 = 0 give y = 64/x2 and then x = 64x4/4096, that is x3 = 64, x = 4, y = 4, h = 2. S = 16 + 16 + 16 = 48 m2. The test: Sxx = 128/x3 = 2, Syy = 2, Sxy = 1, D = 3 > 0 and Sxx > 0: a minimum.
Example 9: least squares
The line y = mx + c fitted to the points (0, 1), (1, 2), (2, 4) minimizes E(m, c) = Σ(mxi + c − yi)2. Setting Em = Ec = 0 gives the normal equations 5m + 3c = 10 and 3m + 3c = 7, so m = 1.5 and c = 5/6. The second derivatives Emm = 10, Ecc = 6, Emc = 6 give D = 24 > 0, a minimum.
Table of the second derivative test
| D | fxx | Conclusion | Example |
|---|---|---|---|
| > 0 | > 0 | local minimum | x2 + y2 at (0, 0) |
| > 0 | < 0 | local maximum | −x2 − y2 at (0, 0) |
| < 0 | any | saddle point | x2 − y2 at (0, 0) |
| = 0 | any | inconclusive | x4 + y4, x3 + y3 |
Where does the theory come from?
Lagrange gave conditions for extrema of functions of several variables in 1759 and introduced the method of multipliers in his Mécanique analytique (1788). The Hessian matrix is named after Ludwig Otto Hesse, who used it in 1842 in the study of curves and surfaces. Legendre’s work on least squares (1805) is one of the earliest practical applications of minimizing a function of two variables.
Which mistakes are common?
Accepting every critical point as an extremum
Critical points include saddles. Always classify them.
Forgetting the boundary
Absolute extrema on a closed region can occur on the boundary even where there are no critical points inside.
Using the wrong sign convention for D
D = fxxfyy − fxy2, not the sum. A negative D means a saddle, whatever the sign of fxx.
Dropping solutions when solving fx = fy = 0
When solving the nonlinear system, divide only by nonzero quantities; dividing by x loses the solution x = 0 (Example 3).