Concept map / Derivatives
Share
Derivatives and local maxima
Estimate a tangent slope by bringing two points together, then use sign changes in the derivative to identify local extrema.
1The slope of a curve at one point
A straight line has one slope: rise over run. A curve is steeper in some places than in others, so what is its slope at a single point? Take a second point a gap h away and find the slope of the line through both. Then shrink h. The number that slope settles on is the derivative.
Pick a curve, place the point, and shrink h. The lower chart plots the derivative at every place, so you can see where the curve climbs, falls and turns.
You are at p = 0.40. The second point is 0.20 to the right. Between them the height changes by 1.62 over a run of 0.20, so the line through both has slope 8.11. As the gap shrinks to nothing the slope settles at 12.50, still 4.39 away. That settled number is the derivative at p = 0.40: the curve is climbing as you move right.
More controls
Uphill is to the right. Steeper ground gives a longer step.
2Find the hilltop from its slope alone
This chart is not the ground. It is the slope of some ground you cannot see: above zero where the hidden ground climbs as you walk right, below zero where it falls. Three places are marked. Where is the top of the hidden hill?
3Bring the second point closer
A slope needs two points: the rise divided by the run. A curve is steeper in some places than others, so that answer depends on where the second point is. Bring it closer and watch which number the slope settles on. Point at a part of the formula to light it up in the top chart.
With your settings: (−6.32 − (−7.95)) / 0.20 = 1.62 / 0.20 = 8.11.
The derivative f′(x) is the number that rise ÷ run approaches as h goes to zero. h cannot be exactly zero, since that would divide zero by zero. Doing this at every x gives the green curve in the lower chart.
Show the slopes for smaller and smaller h
| Gap h at p = 0.40 | Rise ÷ run | Distance from the settled value |
|---|---|---|
| 0.20 | 8.109 | 4.39 |
| 0.020 | 11.991 | 0.51 |
| 0.0020 | 12.448 | 0.052 |
| 0.00020 | 12.495 | 0.0052 |
| shrunk to nothing | 12.500 | 0.00 |
Each time the gap is ten times smaller, the two-point slope lands about ten times closer.
The formula for f′ on this curve
The rules of calculus turn the limit into this formula. You do not need them here: the lower chart plots it, and the table shows the two-point slopes closing in on it.
4Zero slope: a peak, or not
The ground is flat at the top of a hill, so the derivative is zero there. Flat ground alone does not make a peak, though. A peak needs uphill just before and downhill just after. On the lower chart, the derivative crosses zero from the shaded uphill region into the downhill one.
| Flat place on this curve | Slope just before | Slope there | Slope just after | So it is |
|---|---|---|---|---|
| p = 0.70 | 0.47 | 0.00 | −0.49 | a peak: up, then down |
"Just before" and "just after" are one slider notch (0.01) to either side. This hill has a single peak, so stepping uphill from anywhere on it ends at the same place.
5Check yourself
The tasks use the curve buttons, sliders and point in section 1 and tick themselves when you meet them.
- On the hill, put the point at p = 0.50 and shrink h until the slope through the two points is within 0.05 of the slope at the point, which is 8.00.Now: p = 0.40, h = 0.20, two-point slope 8.11, off by 4.39
- On the peak and valley curve, find a place where the slope is zero that is not a peak.Now: you are on a different curve
- On the S-curve, find the ability where the curve is steepest, which is where the derivative curve is at its highest.Now: you are on a different curve
6Slopes and the peak in R
D() differentiates the hill curve exactly. The snippet starts where the lab starts, at p = 0.4 with a gap of 0.2, so the first slope is 8.11. Smaller gaps approach the tangent slope of 12.5, and optimize() finds the peak at 0.7.
Secant slopes, the exact derivative and the peakShow the code
# Log-likelihood of 7 heads in 10 flips, the page's hill
f <- function(p) 7 * log(p) + 3 * log(1 - p)
# Its exact derivative, by symbolic differentiation
df <- D(quote(7 * log(p) + 3 * log(1 - p)), "p")
df
# Slope through two points at p = 0.4 as the gap h shrinks
p <- 0.4
h <- c(0.2, 0.02, 0.002)
data.frame(h, slope = round((f(p + h) - f(p)) / h, 2))
# The tangent slope at p = 0.4
eval(df)
# The peak, where the derivative is zero
round(optimize(f, c(0.3, 0.9), maximum = TRUE)$maximum, 3)Uses base R only.
What the derivative tells you
- The line through two points on a curve has slope rise ÷ run. As the second point closes in, that slope settles on the slope of the tangent, which is the derivative.
- Where the derivative is positive the curve climbs as you move right, and where it is negative the curve falls.
- A peak is where the derivative crosses zero from positive to negative, and a valley is where it crosses from negative to positive. A zero alone does not tell you which.
- Stepping uphill reaches the nearest peak, which need not be the highest one.
- Derivatives find the peak of a likelihood when ability is estimated, and measure how fast an item response probability changes with ability.
Recommended reading
- Calculus Volume 1Gilbert Strang and Edwin Herman§3.1, the derivative as the limit of secant slopes