Local Maxima and Minima

The tallest hill in your county is a real summit: stand on top of it and every direction is downhill. But it is not Everest. A company's best quarter this year is a genuine peak in its revenue graph — but it may be nowhere near the best quarter in the company's history. Both are best around here without being best ever, and calculus makes that distinction precise.

A local maximum is a point higher than everything nearby — the top of a hill, whether or not a bigger mountain looms further along. A local minimum is lower than everything nearby — the bottom of a valley. Together they are the local extrema of the function. The picture below has three summits: each one is a perfectly good local maximum, but only the rightmost is the global maximum on this stretch — the dashed line shows that nothing else reaches its height.

We already know that these turning points can only happen at critical points — places where f'(x) = 0 (or f' doesn't exist). But not every critical point is a peak or a valley: some are mere pauses where the curve flattens for an instant and carries on. So this page builds the two standard tests that sort critical points into maxima, minima, and neither.

Test 1: the first-derivative test

Walk left to right through a critical point and watch how the slope's sign changes. Approaching a hilltop you climb (f' > 0); leaving it you descend (f' < 0). A valley is the reverse. And if the sign never flips, the curve only paused — think of x^3 at the origin, which flattens momentarily and then keeps rising.

\overbrace{f' > 0}^{\nearrow}\;\big|\;\overbrace{f' < 0}^{\searrow} \;\Rightarrow\; \textbf{max} \qquad\qquad \overbrace{f' < 0}^{\searrow}\;\big|\;\overbrace{f' > 0}^{\nearrow} \;\Rightarrow\; \textbf{min}

Let c be a critical point of a function f that is continuous at c and differentiable on either side of it. Then, moving left to right across c:

The test is completely reliable — it reads the actual up/down behaviour of the curve — and it never shrugs. Its only cost is bookkeeping: you must check the sign of f' on both sides of every critical point, which is where a sign table earns its keep (worked example below).

See the sign flip

Here is f(x) = x^3 - 3x with three things drawn at once: the curve itself (thick), its derivative f' (thin, dashed), and the tangent line at the marker. Slide the marker through x = -1 and watch the tangent tilt: it slopes up on the approach, lies exactly flat at the summit, then slopes down — the + \to - flip of a local max. Through x = 1 the story runs in reverse: - \to +, a local min.

Now read the same story off the dashed f' curve instead: it crosses zero downward at the max and upward at the min. That crossing direction is the first-derivative test, drawn as a picture — and the slope of f' at those crossings is a preview of the second test below.

Worked example 1 — the first-derivative test, with a sign table

Classify the critical points of f(x) = x^3 - 3x.

Step 1 — find the critical points. f'(x) = 3x^2 - 3 = 3(x-1)(x+1), which is zero at x = -1 and x = 1.

Step 2 — build a sign table. The two critical points split the line into three intervals; test one convenient point in each:

f'(-2) = 9 > 0,\qquad f'(0) = -3 < 0,\qquad f'(2) = 9 > 0
interval x < -1 x = -1 -1 < x < 1 x = 1 x > 1
sign of f' + 0 0 +
shape \nearrow max \searrow min \nearrow

Step 3 — read off the verdicts. At x = -1 the slope flips + \to -: a local maximum, with value f(-1) = 2. At x = 1 it flips - \to +: a local minimum, value f(1) = -2. Step the diagram below to watch the verdict assemble itself piece by piece.

Test 2: the second-derivative test

There is a faster test, and it only needs one number per critical point. The second derivative f'' measures how the curve bends. Where f'' > 0 the curve is bending upward — shaped like a smile \cup, the kind of shape that "holds water". Where f'' < 0 it bends downward — a frown \cap. Now put a flat tangent (f'(c) = 0) on each shape: a flat spot on a smile can only be the bottom of the smile, and a flat spot on a frown can only be its top.

Suppose f'(c) = 0 and f'' exists at c. Then:

A memory hook that has rescued generations of students: positive second derivative, positive mood\cup smiles, and the flat point at the bottom is a minimum; negative second derivative frowns \cap, and the flat point on top is a maximum. (Yes, the max goes with the negative sign — say the mnemonic to yourself until that stops feeling backwards.)

Worked example 2 — the same cubic, the fast way. Take f(x) = x^3 - 3x again, with critical points x = \pm 1. Differentiate once more:

f''(x) = 6x \qquad\Longrightarrow\qquad f''(-1) = -6 < 0, \qquad f''(1) = 6 > 0

Done. f''(-1) < 0: the curve frowns at x = -1, so that flat point is a local maximum. f''(1) > 0: it smiles at x = 1, a local minimum. Exactly the verdicts of the sign table in worked example 1 — but two substitutions instead of three intervals. When f'' is easy to compute and nonzero at the critical points, this is the test to reach for.

Worked example 3 — when the second-derivative test fails

Classify the critical point of f(x) = x^4.

Step 1 — critical points. f'(x) = 4x^3, zero only at x = 0.

Step 2 — try the second-derivative test. f''(x) = 12x^2, so f''(0) = 0. The test is inconclusive — it does not say "neither"; it says nothing at all. We are not stuck, though: the first-derivative test always has an answer.

Step 3 — fall back to the first-derivative test. Check the sign of f'(x) = 4x^3 either side of zero:

f'(-1) = -4 < 0, \qquad f'(1) = 4 > 0 \qquad\Longrightarrow\qquad -\to+ \;:\; \textbf{local minimum}

So x^4 has a perfectly ordinary local minimum at the origin — the second derivative simply wasn't sharp enough to see it, because the curve is unusually flat there. And that flatness is exactly why the inconclusive case is genuinely ambiguous. The chart below shows three functions that all have f'(0) = 0 and f''(0) = 0 — the second-derivative test draws a blank on every one of them — yet x^4 has a minimum, -x^4 has a maximum, and x^3 has neither. Same test result, three different truths: no rule of the form "f''(c)=0 means such-and-such" could ever work.

Training a neural network is one gigantic minimisation problem: the "loss" measures how wrong the model is, and training means walking downhill on the loss landscape. The algorithm — gradient descent — is the first-derivative test turned into a hiking strategy: compute the slope where you stand, take a small step in the downhill direction, repeat. When the slope reaches zero, you stop.

But "slope zero" only means a critical point — and a hiker who only ever walks downhill gets trapped in the first valley they wander into, a local minimum that may be far worse than the global one. In the 2D landscapes of this page that sounds fatal. The surprising rescue is dimension: a modern network's landscape has millions of directions, and for a critical point to be a true local minimum the curve must bend upward in every single one. That is astronomically unlikely, so most flat points up there are saddle points — mountain passes, min along one direction and max along another — and there is always some direction that still leads downhill. Randomness in the descent (the "stochastic" in stochastic gradient descent) jiggles the hiker off the pass. So the mathematics of this page is, quite literally, the reason your phone's speech recognition trains at all.

The classification recipe

Pulling the whole page into one workflow — this is the routine to run in an exam:

  1. Differentiate and solve f'(x) = 0 to list the critical points.
  2. Try the second-derivative test first (it's quicker): compute f'' at each critical point. Negative → local max; positive → local min.
  3. If f''(c) = 0 (or f'' is painful to compute), use the first-derivative test: a sign table for f' around c. It always gives an answer.
  4. If you need the global extremum on an interval, evaluate f at every critical point and at the endpoints, then compare the values.

Watch it on Khan Academy