Skip to content
DoingCamp CS

Make it comfy

Lesson style

Quick mode shows the key picture, a summary and the practice. Good for a refresher.

Theme
Font

Both fonts are designed to be easy to read. Some readers with dyslexia prefer Lexend.

Text size
Spacing
Animations

Lesson 3 of 20 · about 16 min

The derivative

Shrink the time gap to zero, in the limit sense, and the average speed becomes the speed at one instant. That's the derivative, the slope of the curve at a single point. You'll watch a secant line turn into a tangent, trace out the speed of the Big Drop rider at every moment, and write the code behind the ride's speed display, including the trap of making the gap too small.

🧭 What you need first: Limits

The story

The manager wants a big screen at the bottom of the Big Drop showing each rider’s top speed, like a radar gun. Lesson 2 found the speed at t=1t = 1: the average speed from 1 to 1+k1 + k approaches 9.8 m/s as k→0k \to 0.

That number has a name: the derivative of hh at t=1t = 1, written h′(1)h'(1). In 1665–66, a young Isaac Newton developed the idea (he called it a “fluxion”) to describe moving planets; around 1675, Gottfried Leibniz invented it independently and gave it the dydx\frac{dy}{dx} notation we still use. Their two methods became calculus, and the derivative is its first great idea.

Today you’ll see the derivative two ways, as a speed and as a slope, and then write the speed display.

Another way: zoom in on a curve

Take any smooth curve and zoom in on one point, more and more. The curve looks less and less curved, until it looks like a straight line. The slope of that line is the derivative there. Calculus works because smooth curves are “locally straight”.

Play with it

From secant to tangent

The green dashed line is the tangent at t=at = a. Shrink the gap hh and watch the purple secant swing onto it.

🎯 1/2: At a = 1, shrink h to 0.01 or less. What slope does the secant settle on?

Slide the start a and the gap h. The purple line joins the two orange points; its slope is the average rate of change between them.

h(t) = 12 − 4.9t²

from 1 to 1.5: Δ = −6.125 over 0.5

average rate = −6.125 ÷ 0.5 = −12.25 m/s

Green dashed: the tangent at a, slope −9.8 m/s. Shrink h and the purple line closes in on it.

The rider is at −4.9 m/s at t = 0.5 and −9.8 m/s at t = 1. What do you predict at t = 1.5?

Trace the speed at every moment

🎯 1/2: Slide t across the whole ride to trace the rider's rate of change of height.

Slide x. Top: h(t) = 12 − 4.9t² with its tangent line (green). Bottom: each tangent's slope, plotted as a dot. Sweep across to draw the derivative.

t = 0: f = 12, slope of tangent = 0

Traced 0% of the range. Sweep further to reveal the whole derivative.

The dots fall on a straight line through the origin: h′(t)=−9.8th'(t) = -9.8t. A curving graph of height has a straight-line graph of speed.

Name it

The real words

  • The Derivative of ff at aa:

    f′(a)=lim⁡h→0f(a+h)−f(a)hf'(a) = \lim_{h \to 0} \frac{f(a + h) - f(a)}{h}

    if that limit exists. It’s the instantaneous rate of change, measured in (units of ff) per (units of xx).

  • Leibniz notation: dfdx\frac{df}{dx} or dydx\frac{dy}{dx}, read “dy by dx”: a tiny change in yy over a tiny change in xx. For time, physicists often write h˙\dot{h}.

  • The Tangent line at aa passes through (a,f(a))(a, f(a)) with slope f′(a)f'(a):

    y=f(a)+f′(a) (x−a)y = f(a) + f'(a)\,(x - a)
  • Working out the Big Drop’s derivative from the definition:

    h(t+k)−h(t)=−4.9((t+k)2−t2)=−4.9(2tk+k2)\begin{aligned} h(t + k) - h(t) &= -4.9\big((t + k)^2 - t^2\big) \\ &= -4.9(2tk + k^2) \end{aligned}

    Divide by kk: −9.8t−4.9k-9.8t - 4.9k. As k→0k \to 0 this approaches −9.8t-9.8t. So h′(t)=−9.8th'(t) = -9.8t for every tt.

  • The derivative function f′(x)f'(x) gives the slope at every xx. Where ff rises, f′>0f' > 0; where it falls, f′<0f' < 0; at a flat peak or valley, f′=0f' = 0.

  • Not every function has a derivative everywhere: ∣x∣|x| has a sharp corner at 0, where the slopes from the left (−1) and right (1) disagree.

Build it

A numerical derivative

When you only have code for ff, not a formula for f′f', you can estimate the derivative with a small hh.

Write forward(f, x, h) = (f(x + h) − f(x)) / h and central(f, x, h) = (f(x + h) − f(x − h)) / (2h). Then error(method, h): how far method(drop, 1, h) is from the true value −9.8 (absolute value). The Big Drop's height function drop(t) is included.

With h=10−15h = 10^{-15}, f(x+h)f(x + h) and f(x)f(x) agree in almost all of their 16 significant digits, so their difference is mostly rounding noise. Numerical programmers pick hh around 10−510^{-5} to 10−810^{-8} for this reason.

Challenge

The speed display

Write speed_kmh(t): the rider's speed at time t in km/h, using central(drop, t, 1e-5), its absolute value, times 3.6 (1 m/s = 3.6 km/h). Then splash_time(): when the rider reaches height 0, which is √(12 / 4.9). And top_speed(): the speed in km/h at splash_time().

About 55 km/h after falling 12 m, if nothing slowed the rider. Real drop slides are a little slower because of water and air friction, which is why the engineers will later measure the real ride and fit a better model.

Remember it

f′(3) = −2. What does that tell you?

Got it?

Finish the lesson to color it in on your map and collect its concept cards.

Did this lesson click?