TExcelTAD
Home › Calculus in Depth › How Derivatives Affect the Shape of a Graph

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 f′(x)>0f'(x) > 0 on an interval, ff is increasing there. If f′(x)<0f'(x) < 0, ff is decreasing.

Proof. For x1<x2x_1 < x_2 in the interval, the Mean Value Theorem gives f(x2)−f(x1)=f′(c)(x2−x1)f(x_2) - f(x_1) = f'(c)(x_2 - x_1) for some cc between them. The factor x2−x1x_2 - x_1 is positive, so the sign of the difference is the sign of f′(c)f'(c). ∎

The converse is only half true: x3x^3 is increasing on all of R\mathbb{R} though f′(0)=0f'(0) = 0. A positive derivative is sufficient, not necessary.

The First Derivative Test

Let cc be a critical number of a continuous ff.

Sign of f′f' left of cc → right of cc Conclusion at cc
+→−+ \to - local maximum
−→+- \to + local minimum
same sign on both sides no local extremum

This test works even where f′(c)f'(c) does not exist (cusps and corners), which makes it the most reliable of the tests.

Concavity and inflection points

ff 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 f′′(x)>0f''(x) > 0 on an interval, ff is concave upward there; if f′′(x)<0f''(x) < 0, concave downward.

Proof sketch (upward case). Fix aa and compare ff with its tangent T(x)=f(a)+f′(a)(x−a)T(x) = f(a) + f'(a)(x - a). By the MVT, f(x)−f(a)=f′(c)(x−a)f(x) - f(a) = f'(c)(x - a) for cc between aa and xx, so f(x)−T(x)=(f′(c)−f′(a))(x−a)f(x) - T(x) = (f'(c) - f'(a))(x - a). Because f′′>0f'' > 0, f′f' is increasing (I/D Test applied to f′f'), so f′(c)−f′(a)f'(c) - f'(a) has the same sign as c−ac - a, which is the sign of x−ax - a. The product is positive: f(x)>T(x)f(x) > T(x). ∎

Note: f′′(c)=0f''(c) = 0 does not make cc an inflection point. x4x^4 has f′′(0)=0f''(0) = 0 and is concave up on both sides. What matters is a sign change of f′′f''.

The Second Derivative Test

Second Derivative Test. Suppose f′′f'' is continuous near cc and f′(c)=0f'(c) = 0. If f′′(c)>0f''(c) > 0, ff has a local minimum at cc; if f′′(c)<0f''(c) < 0, a local maximum. If f′′(c)=0f''(c) = 0, the test says nothing.

The last line is important: x3x^3, x4x^4 and −x4-x^4 all have f′(0)=f′′(0)=0f'(0) = f''(0) = 0, and they show neither, a minimum and a maximum respectively.

Putting it together

For f(x)=x4−4x3f(x) = x^4 - 4x^3, find intervals of monotonicity and concavity, extrema and inflection points:

python · try it yourself
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 x=0x = 0 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 f′′f'' changes sign there. The only local (and absolute) minimum is f(3)=−27f(3) = -27. The second inflection point is at x=2x = 2.

The picture

python · try it yourself
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 x3x^3 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 f′′≥0f'' \ge 0 is the 1-D version of the convexity checks used in optimisation libraries.

Exercises

Exercise 1: Sign chart

Find where f(x)=x3−6x2+9x+1f(x) = x^3 - 6x^2 + 9x + 1 increases and decreases, and classify its critical numbers.

Answer

Increasing on (−∞,1)(-\infty, 1) and (3,∞)(3, \infty), decreasing on (1,3)(1, 3); local max f(1)=5f(1) = 5, local min f(3)=1f(3) = 1.

Solution
f′(x)=3x2−12x+9=3(x−1)(x−3)x<1:(−)(−)>01<x<3:(+)(−)<0x>3:(+)(+)>0f(1)=1−6+9+1=5,f(3)=27−54+27+1=1\begin{aligned} &f'(x) = 3x^2 - 12x + 9 = 3(x - 1)(x - 3) \\ &x < 1: (-)(-) > 0 \qquad 1 < x < 3: (+)(-) < 0 \qquad x > 3: (+)(+) > 0 \\ &f(1) = 1 - 6 + 9 + 1 = 5, \qquad f(3) = 27 - 54 + 27 + 1 = 1 \end{aligned}

Exercise 2: Inflection point

Find the inflection point of the same ff.

Answer

(2,3)(2, 3).

Solution

f′′(x)=6x−12f''(x) = 6x - 12 is negative for x<2x < 2 and positive for x>2x > 2, so the concavity changes at x=2x = 2, where f(2)=8−24+18+1=3f(2) = 8 - 24 + 18 + 1 = 3.

Exercise 3: When the second test fails

For g(x)=x5−5x4g(x) = x^5 - 5x^4, the Second Derivative Test at x=0x = 0 is inconclusive. Use the first derivative test instead.

Answer

gg has a local maximum at x=0x = 0.

Solution
g′(x)=5x4−20x3=5x3(x−4);g′′(x)=20x3−60x2, so g′′(0)=0 (inconclusive)near 0: x<0⇒5x3<0 and x−4<0⇒g′>0near 0: 0<x<4⇒5x3>0 and x−4<0⇒g′<0+→−:local maximum, g(0)=0\begin{aligned} &g'(x) = 5x^4 - 20x^3 = 5x^3(x - 4); \quad g''(x) = 20x^3 - 60x^2, \text{ so } g''(0) = 0 \text{ (inconclusive)} \\ &\text{near } 0\text{: } x < 0 \Rightarrow 5x^3 < 0 \text{ and } x - 4 < 0 \Rightarrow g' > 0 \\ &\phantom{\text{near } 0\text{: }} 0 < x < 4 \Rightarrow 5x^3 > 0 \text{ and } x - 4 < 0 \Rightarrow g' < 0 \\ &+ \to - : \text{local maximum}, \ g(0) = 0 \end{aligned}
python · try it yourself
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 σ(x)=11+e−x\sigma(x) = \frac{1}{1 + e^{-x}} has an inflection point at x=0x = 0. (Hint: σ′=σ(1−σ)\sigma' = \sigma(1 - \sigma).)

Answer

σ′′=σ(1−σ)(1−2σ)\sigma'' = \sigma(1 - \sigma)(1 - 2\sigma) changes sign where σ=1/2\sigma = 1/2, i.e. at x=0x = 0.

Solution

Differentiate σ′=σ−σ2\sigma' = \sigma - \sigma^2: σ′′=σ′−2σσ′=σ′(1−2σ)\sigma'' = \sigma' - 2\sigma\sigma' = \sigma'(1 - 2\sigma). Since σ′>0\sigma' > 0, the sign of σ′′\sigma'' is the sign of 1−2σ1 - 2\sigma: positive for x<0x < 0 (σ<1/2\sigma < 1/2), negative for x>0x > 0. So the sigmoid, used everywhere in ML, is steepest at 0.

python · try it yourself
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

f′(c)=0f'(c) = 0 and f′′(c)=0f''(c) = 0. What does the Second Derivative Test conclude?

  1. Local minimum
  2. Local maximum
  3. Inflection point
  4. Nothing: the test is inconclusive

Which result is used to prove the Increasing/Decreasing Test?

  1. The Intermediate Value Theorem
  2. The Mean Value Theorem
  3. l'Hospital's Rule
  4. The Fundamental Theorem of Calculus

f′f' changes from negative to positive at cc. What is at cc?

  1. A local minimum
  2. A local maximum
  3. An inflection point
  4. A vertical asymptote