19  Second Derivative Test

19.1 Exploratory unit

NoteRemark
  • \(f_{xx}(x_0,y_0)\) measures the concavity (in the \(x\)-direction) of the function \(f\) at the point \((x_0,y_0)\).
  • \(f_{yy}(x_0,y_0)\) measures the concavity (in the \(y\)-direction) of the function \(f\) at the point \((x_0,y_0)\).
  • \(f_{xy}(x_0,y_0)\) measures the cross-concavity of the function \(f\) at the point \((x_0,y_0)\).

19.2 Main result

TipSecond derivative test (Stewart et al. 2020, 14.7.3)

Suppose that \((x_0,y_0)\) is a critical point of \(f(x,y),\) and set \[ D = D(x_0, y_0) = f_{xx}(x_0,y_0)f_{yy}(x_0,y_0) - f_{xy}(x_0,y_0)^2\]

  • If \(D > 0,\) then \(f\) has a local extrema at \((x_0,y_0)\):
    • If \(f_{xx}(x_0,y_0) > 0,\) then \(f\) has a local minimum at \((x_0,y_0)\).
    • If \(f_{xx}(x_0,y_0) < 0,\) then \(f\) has a local maximum at \((x_0,y_0)\).
  • If \(D < 0,\) then \(f\) has a saddle point at \((x_0,y_0)\).
  • If \(D = 0,\) then the test is inconclusive.
NoteRemark

If \(D\) is positive, i.e., if \(f\) has an extrema at \((x_0,y_0),\) then we must have

  • \(f_{xx}(x_0,y_0) > 0\) and \(f_{yy}(x_0,y_0) > 0,\) or
  • \(f_{xx}(x_0,y_0) < 0\) and \(f_{yy}(x_0,y_0) < 0\).

This follows as the \(-f_{xy}^2\) term in \(D\) is always nonpositive, so \(f_{xx} f_{yy}\) must be positive to make \(D\) positive.

CautionSpoiler alert

The \(D\) of the second derivative test is the determinant of a matrix (the Hessian): \[D = \begin{vmatrix} f_{xx} & f_{xy}\\ f_{yx} & f_{yy} \end{vmatrix} = f_{xx}f_{yy} - f_{xy}^2,\] where we lean on Clairaut’s theorem (\(f_{xy} = f_{yx}\)). As will be discussed in future courses, this interpretation of \(D\) provides geometric data in the language of linear algebra. While we won’t use this fact in this class, it is a handy way to remember the formula for \(D\)!

19.3 Homework

19.4 Review

ImportantBig idea

The second derivative test gives us a way to classify critical values of \(f(x,y)\).

NoteRemark
  • The pure second derivatives ask how much a function looks like a paraboloid at the origin. \[f(x,y) = \tfrac{1}{2} ( x^2 + y^2 ) \quad \implies \quad f_{xx}(0,0) = 1 = f_{yy}(0,0) \text{ and } f_{xy}(0,0) = 0.\]

  • The mixed second derivative \(f_{xy}(x_0,y_0)\) asks how much a function looks like a saddle at the origin. \[f(x,y) = xy \quad \implies \quad f_{xx}(0,0) = 0 = f_{yy}(0,0) \text{ and } f_{xy}(0,0) = 1.\]

The \(D\) of the second derivative test is a tug-of-war between the pure second derivatives and the mixed second derivative: does the function look more like a paraboloid or a saddle near the critical point?

We can visualize this tug of war by considering the function \(f(x,y) = \frac{1}{2}(x^2 + y^2) - a xy,\) as the parameter \(a\) varies, using both contours and the \(z = f(x,y)\) surface plot.

var('x y z')
frames2d = [
    contour_plot(
      (x^2 + y^2)/2 - a*x*y, 
      (x, -2, 2), (y, -2, 2), 
      contours=12, cmap='Spectral',
    )
    for a in srange(-2, 2.1, 0.1)
]
frames3d = [
    implicit_plot3d(
      z == (x^2 + y^2)/2 - a*x*y, 
      (x, -2, 2), (y, -2, 2), (z, -2, 2), 
      color='cyan', opacity=0.8,
    )
    for a in srange(-2, 2.1, 0.1)
]
animate(frames2d).show()
animate(frames3d).show()

19.5 More examples

ImportantProcedure: Second derivative test

Given \(f(x,y),\) we want to find and classify its critical points: maybe we want to find its maximum or minimum values, or are interested in some other phenomenon.

  1. Compute the gradient, \(\nabla f = \langle f_x, f_y \rangle,\)
  2. Set \(\nabla f = 0\) (a system of equations) and solve to find critical points,
  3. Compute the second derivatives (\(f_{xx}, f_{yy}, f_{xy}\)) and write \(D = f_{xx} f_{yy} - f_{xy}^2,\) and
  4. Classify the critical points via the second derivative test.
ImportantSageMath

The algebra (not the calculus!) in Step 2 is the hardest part of this Procedure. You should practice solving these problems by hand!—but you should also use SageMath to check your work. Sage can:

  • Compute partial derivatives
var('x y')
f = x^4 + y^4 - 4*x*y

fx = diff(f, x)
fy = diff(f, y)

fxx = diff(fx, x)
fyy = diff(fy, y)
fxy = diff(fx, y)

D = fxx*fyy - fxy^2

print(f"The first partial derivatives are {fx} and {fy}.")
print(f"The second derivative discriminant is {D}.")
The first partial derivatives are 4*x^3 - 4*y and 4*y^3 - 4*x.
The second derivative discriminant is 144*x^2*y^2 - 16.
  • Solve systems of equations (and filter out complex solutions!)
solutions = solve([fx==0, fy==0], x, y)
real_solutions = [
    sol for sol in solutions
    if all(expr.rhs().imag() == 0 for expr in sol)
]
print("The real critical points are:", real_solutions)
The real critical points are: [[x == -1, y == -1], [x == 1, y == 1], [x == 0, y == 0]]
  • Evaluate functions at specific points
for sol in real_solutions:
  print(f"{sol} gives D = {D.subs(sol)}")
[x == -1, y == -1] gives D = 128
[x == 1, y == 1] gives D = 128
[x == 0, y == 0] gives D = -16
NoteExample: critical points of Patrick’s pants

Let’s see how the algebra works out. We have the system \(4x^3 - 4y = 0\) and \(4y^3 - 4x = 0\). Thus

flowchart LR
  A("2x = λ 2x <br> 4y = λ 2y <br> x² + y² = 1")
  A --> B("2x (1-λ) = 0 <br> 2y (2-λ) = 0 <br> x² + y² = 1")
  B -->|"x=0"| C("2y (2-λ) = 0 <br> y² = 1")
  B -->|"λ=1"| D("2y = 0 <br> x² + y² = 1")
  C -->|"y=0"| E("0 = 1"):::contradiction
  C -->|"λ=2"| F("y² = 1")
  F -->|"y=±1"| G("(x,y,λ) = (0,1,2), (0,-1,2)"):::solution
  D -->|"y=0"| H("x² = 1")
  H -->|"x=±1"| I("(x,y,λ) = (1,0,1), (-1,0,1)"):::solution

Using the results from the previous block, we see that

  • \((-1,-1)\) and \((1,1)\) are extrema of \(f(x,y)\)
  • \((0,0)\) is a saddle point.

To check what type of extrema we have, we evaluate either \(f_{xx}\) or \(f_{yy}\) at the point—their signs must be the same! For good measure, we will also evaluate the function at the points, just to see what we can see.

for sol in real_solutions:
  print(f"{sol} gives f = {f.subs(sol)} and fxx = {fxx.subs(sol)}")
[x == -1, y == -1] gives f = -2 and fxx = 12
[x == 1, y == 1] gives f = -2 and fxx = 12
[x == 0, y == 0] gives f = 0 and fxx = 0

In particular, \(f_{xx} > 0\) at \((x,y)=(-1,-1)\) and \((1,1),\) so these are local minima!

NoteExample: critical points of \(f(x,y) = (x^2 + y^2) e^{-x}\)

Computing the gradient is a bit more work, since we need to use the product rule:

\[\nabla f = \langle 2x e^{-x} - (x^2 + y^2) e^{-x}, 2y e^{-x} \rangle = e^{-x} \langle -x^2 + 2x - y^2, 2y \rangle.\]

Since \(e^{-x} > 0\) for all \(x,\) the critical points are determined by the equation \(\langle -x^2 + 2x - y^2, 2y \rangle = \vec{0}\).

flowchart LR
  A("-x²+2x-y² = 0 <br> 2y = 0")
  A --> B("x(2-x) = 0 <br> y = 0")
  B -->|"x=0"| C("(x,y) = (0,0)"):::solution
  B -->|"x=2"| D("(x,y) = (2,0)"):::solution

We compute \(f_{xx} = (x^2+y^2-4x+2)e^{-x},\) \(f_{xy} = -2 e^{-x} y,\) and \(f_{yy} = 2 e^{-x},\) so \[D = 2 (x^2-y^2-4x+2) e^{-2x}.\] Ultimately, we see that \((0,0)\) is a local minimum (\(D=4, f_{xx}=2\)), and \((2,0)\) is a saddle (\(D=-\frac{4}{e^4}\)).

NoteExample: critical points of \(f(x,y) = x y - x^2 y - x y^2\)

We have \(\nabla f = \langle y(1-2x-y), x(1-x-2y) \rangle\). Thus we have:

flowchart LR
  A("y(1-2x-y) = 0 <br> x(1-x-2y) = 0")
  A -->|"y=0"| B("x(1-x)=0")
  A -->|"y=1-2x"| C("x(3x-1)=0")
  B -->|"x=0"| D("(x,y) = (0,0)"):::solution
  B -->|"x=1"| E("(x,y) = (1,0)"):::solution
  C -->|"x=0"| F("(x,y) = (0,1)"):::solution
  C -->|"x=1/3"| G("(x,y) = (1/3,1/3)"):::solution

So there are four critical points: \((0,0),\) \((1,0),\) \((0,1),\) and \((\tfrac{1}{3},\tfrac{1}{3})\). Since \(f_{xx} = -2y,\) \(f_{yy} = -2x,\) and \(f_{xy} = 1-2x-2y,\) we have \[ D(0,0) = D(1,0) = D(0,1) = -1 \quad \text{and} \quad D(\tfrac{1}{3},\tfrac{1}{3}) = \tfrac{1}{3}.\] Since \(f_{xx}(\tfrac{1}{3},\tfrac{1}{3}) = -\tfrac{2}{3},\) the first three of these are saddles and the last is a local maximum.

19.6 Homework