How Derivatives Affect the Shape of a Graph
The first derivative tells you where a graph rises and falls; the second tells you which way it bends. This lesson states the Increasing/Decreasing Test, the First and Second Derivative Tests and the Concavity Test, proves them from the Mean Value Theorem, and shows where each one can mislead you. The survey version is in Higher Derivatives and Extrema.
Increasing and decreasing
I/D Test. If on an interval, is increasing there. If , is decreasing.
Proof. For in the interval, the Mean Value Theorem gives for some between them. The factor is positive, so the sign of the difference is the sign of . ∎
The converse is only half true: is increasing on all of though . A positive derivative is sufficient, not necessary.
The First Derivative Test
Let be a critical number of a continuous .
| Sign of left of → right of | Conclusion at |
|---|---|
| local maximum | |
| local minimum | |
| same sign on both sides | no local extremum |
This test works even where does not exist (cusps and corners), which makes it the most reliable of the tests.
Concavity and inflection points
is concave upward on an interval if its graph lies above all its tangent lines there, concave downward if below. A point where the graph is continuous and the concavity changes is an inflection point.
Concavity Test. If on an interval, is concave upward there; if , concave downward.
Proof sketch (upward case). Fix and compare with its tangent . By the MVT, for between and , so . Because , is increasing (I/D Test applied to ), so has the same sign as , which is the sign of . The product is positive: . ∎
Note: does not make an inflection point. has and is concave up on both sides. What matters is a sign change of .
The Second Derivative Test
Second Derivative Test. Suppose is continuous near and . If , has a local minimum at ; if , a local maximum. If , the test says nothing.
The last line is important: , and all have , and they show neither, a minimum and a maximum respectively.
Putting it together
For , find intervals of monotonicity and concavity, extrema and inflection points:
import sympy as sp
x = sp.symbols('x', real=True)
f = x**4 - 4*x**3
f1, f2 = sp.factor(sp.diff(f, x)), sp.factor(sp.diff(f, x, 2))
print("f' =", f1, " zeros:", sp.solve(f1, x))
print("f'' =", f2, " zeros:", sp.solve(f2, x))
for c in sp.solve(f1, x):
left, right = f1.subs(x, c - sp.Rational(1, 2)), f1.subs(x, c + sp.Rational(1, 2))
kind = {(True, False): "local max", (False, True): "local min"}.get((left > 0, right > 0), "no extremum")
print(f"x = {c}: f' sign {'+' if left > 0 else '-'} -> {'+' if right > 0 else '-'} => {kind}, f = {f.subs(x, c)}")
print("increasing on:", sp.solve_univariate_inequality(f1 > 0, x, relational=False))
print("concave up on:", sp.solve_univariate_inequality(f2 > 0, x, relational=False))f' = 4*x**2*(x - 3) zeros: [0, 3]
f'' = 12*x*(x - 2) zeros: [0, 2]
x = 0: f' sign - -> - => no extremum, f = 0
x = 3: f' sign - -> + => local min, f = -27
increasing on: Interval.open(3, oo)
concave up on: Union(Interval.open(-oo, 0), Interval.open(2, oo))
At the derivative is 0 but keeps its sign (negative on both sides), so there is no extremum, only a horizontal tangent; it is also an inflection point because changes sign there. The only local (and absolute) minimum is . The second inflection point is at .
The picture
import numpy as np
import matplotlib.pyplot as plt
xs = np.linspace(-1.2, 4.2, 400)
f = xs**4 - 4 * xs**3
f2 = 12 * xs**2 - 24 * xs
plt.figure(figsize=(6, 4))
plt.plot(xs, f, label="f(x) = x⁴ − 4x³")
plt.fill_between(xs, -35, 20, where=f2 < 0, alpha=0.12, label="concave down (f″ < 0)")
plt.scatter([0, 2, 3], [0, -16, -27], zorder=3)
plt.annotate("inflection", (0, 0), (0.3, 8)); plt.annotate("inflection", (2, -16), (2.2, -8))
plt.annotate("minimum", (3, -27), (3.1, -32))
plt.ylim(-35, 20); plt.legend(loc="upper right"); plt.grid(alpha=0.3)
print("plotted x^4 - 4x^3 with its concave-down band 0 < x < 2")plotted x^4 - 4x^3 with its concave-down band 0 < x < 2
In software
- Loss curvature. In ML the second derivative of the loss (the Hessian in many dimensions) says whether a stationary point of training is a minimum, a maximum or a saddle. In high dimensions saddles, the analogue of at 0, are far more common than minima.
- Easing curves. An ease-in-out animation curve is concave up in the first half and concave down in the second; the inflection point is where the motion is fastest. Designers tune it by moving that point (Easing Curves).
- Convexity. A function that is concave up everywhere (convex) has at most one minimum value and gradient descent cannot get stuck in a bad local minimum. Checking is the 1-D version of the convexity checks used in optimisation libraries.
Exercises
Exercise 1: Sign chart
Find where increases and decreases, and classify its critical numbers.
Answer
Increasing on and , decreasing on ; local max , local min .
Solution
Exercise 2: Inflection point
Find the inflection point of the same .
Answer
.
Solution
is negative for and positive for , so the concavity changes at , where .
Exercise 3: When the second test fails
For , the Second Derivative Test at is inconclusive. Use the first derivative test instead.
Answer
has a local maximum at .
Solution
g1 = lambda x: 5 * x**4 - 20 * x**3
print(g1(-0.1) > 0, g1(0.1) < 0)True True
Exercise 4: Logistic curve
Show that has an inflection point at . (Hint: .)
Answer
changes sign where , i.e. at .
Solution
Differentiate : . Since , the sign of is the sign of : positive for (), negative for . So the sigmoid, used everywhere in ML, is steepest at 0.
import sympy as sp
x = sp.symbols('x')
s = 1 / (1 + sp.exp(-x))
print(sp.solve(sp.diff(s, x, 2), x))[0]
Test yourself
and . What does the Second Derivative Test conclude?
- Local minimum
- Local maximum
- Inflection point
- Nothing: the test is inconclusive
Which result is used to prove the Increasing/Decreasing Test?
- The Intermediate Value Theorem
- The Mean Value Theorem
- l'Hospital's Rule
- The Fundamental Theorem of Calculus
changes from negative to positive at . What is at ?
- A local minimum
- A local maximum
- An inflection point
- A vertical asymptote