TExcelTAD
Home › Pre-Calculus, Geometry & Trigonometry › A First Look at the Derivative

A First Look at the Derivative

How fast is a car going at exactly 3 seconds? Average speed over an interval is easy: distance divided by time. Speed at one instant is the limit of those averages as the interval shrinks to zero. That limit is the derivative, the central idea of differential calculus. This lesson builds it from slopes of secant lines, computes a few derivatives by hand and numerically, and shows where derivatives appear in code.

From average rate to instantaneous rate

The average rate of change of ff between x=ax = a and x=a+hx = a + h is the slope of the secant line through the two points:

average rate=f(a+h)−f(a)h(the difference quotient)\text{average rate} = \frac{f(a + h) - f(a)}{h} \qquad \text{(the difference quotient)}

As hh shrinks, the second point slides toward the first and the secant line turns into the tangent line, the line that just touches the curve at aa. Its slope is the derivative:

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

The difference quotient has the form 0/00/0 at h=0h = 0, so this is exactly the kind of limit from Introduction to Limits: simplify first, then let h→0h \to 0.

A worked example

A stone falls s(t)=4.9t2s(t) = 4.9t^2 metres after tt seconds. What is its speed at t=3t = 3?

python · try it yourself
def s(t):
    return 4.9 * t**2

print("   h        average speed on [3, 3+h]")
for h in [1, 0.1, 0.01, 0.001, 0.0001]:
    print(f"{h:<8} {(s(3 + h) - s(3)) / h:.6f}")
   h        average speed on [3, 3+h]
1        34.300000
0.1      29.890000
0.01     29.449000
0.001    29.404900
0.0001   29.400490

The averages approach 29.4 m/s29.4\ \text{m/s}. Algebra shows why:

s(3+h)−s(3)h=4.9⋅(3+h)2−9h=4.9⋅6h+h2h=4.9⋅(6+h)  →  4.9⋅6=29.4\frac{s(3 + h) - s(3)}{h} = 4.9 \cdot \frac{(3 + h)^2 - 9}{h} = 4.9 \cdot \frac{6h + h^2}{h} = 4.9 \cdot (6 + h) \;\to\; 4.9 \cdot 6 = 29.4

Doing the same with a general tt instead of 3 gives s′(t)=9.8ts'(t) = 9.8t: the speed grows by 9.8 m/s9.8\ \text{m/s} every second, which is the acceleration due to gravity.

The derivative as a function

Repeating the calculation at every point gives a new function f′(x)f'(x). A few results you will prove in calculus:

f(x)f(x) f′(x)f'(x) Meaning
cc (constant) 0 a flat line has slope 0
mx+bmx + b mm a line has the same slope everywhere
x2x^2 2x2x steeper the further from 0
x3x^3 3x23x^2
xnx^n n⋅xn−1n \cdot x^{n-1} the power rule
sin⁡x\sin x cos⁡x\cos x
exe^x exe^x the function that is its own slope

The sign of f′f' tells you the shape: f′>0f' > 0 where ff increases, f′<0f' < 0 where it decreases, and f′=0f' = 0 at flat points such as the top of a hill or the bottom of a valley. That is how calculus finds maxima and minima.

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

f = lambda x: x**3 - 3 * x
a = 1.5
slope = 3 * a**2 - 3                   # f'(x) = 3x² − 3
x = np.linspace(-2.5, 2.5, 300)

plt.figure(figsize=(6, 4))
plt.plot(x, f(x), "k", lw=2, label="f(x) = x³ − 3x")
for h, style in [(1.0, "C1--"), (0.4, "C2--")]:
    m = (f(a + h) - f(a)) / h
    plt.plot(x, f(a) + m * (x - a), style, label=f"secant, h = {h}: slope {m:.2f}")
plt.plot(x, f(a) + slope * (x - a), "C0", label=f"tangent: slope {slope:.2f}")
plt.plot([a], [f(a)], "ko")
plt.ylim(-4, 6); plt.legend(fontsize=8); plt.grid(alpha=0.3)
print("tangent slope at x = 1.5:", slope)
tangent slope at x = 1.5: 3.75

The secants (dashed) tilt toward the tangent as hh shrinks.

In software

  • Numerical derivatives. Code can approximate f′(a)f'(a) with a small hh. The central difference (f(a+h)−f(a−h))/(2h)(f(a + h) - f(a - h))/(2h) is far more accurate than the one-sided quotient. But hh cannot be too small: floating-point subtraction of nearly equal numbers loses digits.
  • Gradient descent. Training a neural network means nudging each weight against the derivative of the loss, the slope that says which direction is downhill (Gradient Descent). Libraries compute those derivatives exactly with automatic differentiation rather than with small hh.
  • Physics and animation. Velocity is the derivative of position, acceleration the derivative of velocity. A game estimates velocity from two frames as (x2−x1)/dt(x_2 - x_1)/dt: a difference quotient.
python · try it yourself
import math

f, a, exact = math.sin, 1.0, math.cos(1.0)
print("   h       forward error   central error")
for h in [1e-1, 1e-3, 1e-5, 1e-8, 1e-11]:
    fwd = (f(a + h) - f(a)) / h
    cen = (f(a + h) - f(a - h)) / (2 * h)
    print(f"{h:<8.0e} {abs(fwd - exact):14.2e} {abs(cen - exact):14.2e}")
   h       forward error   central error
1e-01          4.29e-02       9.00e-04
1e-03          4.21e-04       9.01e-08
1e-05          4.21e-06       1.11e-11
1e-08          2.97e-09       2.58e-09
1e-11          1.17e-06       1.17e-06

The error first shrinks as hh shrinks (the limit at work), then grows again when rounding dominates. Picking hh well is a real engineering decision. The full story starts in The Derivative and, in depth, Tangents and Velocity and The Derivative as a Function.

Exercises

Exercise 1: Average rate

Find the average rate of change of f(x)=x2+1f(x) = x^2 + 1 from x=1x = 1 to x=4x = 4.

Answer

5

Solution
f(4)−f(1)4−1=17−23=153=5\frac{f(4) - f(1)}{4 - 1} = \frac{17 - 2}{3} = \frac{15}{3} = 5

Exercise 2: Derivative from the definition

Use the limit definition to find f′(x)f'(x) for f(x)=x2−4xf(x) = x^2 - 4x.

Answer

f′(x)=2x−4f'(x) = 2x - 4

Solution
f(x+h)−f(x)=(x+h)2−4(x+h)−x2+4x=2xh+h2−4hdivide by h:2x+h−4  →  2x−4 as h→0\begin{aligned} &f(x + h) - f(x) = (x + h)^2 - 4(x + h) - x^2 + 4x = 2xh + h^2 - 4h \\ &\text{divide by } h{:}\quad 2x + h - 4 \;\to\; 2x - 4 \text{ as } h \to 0 \end{aligned}

Exercise 3: Tangent line

Find the equation of the tangent line to y=x3y = x^3 at x=2x = 2.

Answer

y=12x−16y = 12x - 16

Solution
slope=3⋅22=12,point (2,8)y−8=12(x−2)  ⇒  y=12x−16\begin{aligned} &\text{slope} = 3 \cdot 2^2 = 12, \quad \text{point } (2, 8) \\ &y - 8 = 12(x - 2) \;\Rightarrow\; y = 12x - 16 \end{aligned}
python · try it yourself
f = lambda x: x**3
h = 1e-5
print(round((f(2 + h) - f(2 - h)) / (2 * h), 6))
12.0

Exercise 4: Where is it flat?

f(x)=x3−3xf(x) = x^3 - 3x has f′(x)=3x2−3f'(x) = 3x^2 - 3. Where is the tangent horizontal, and what are the function values there?

Answer

At x=−1x = -1 (f=2f = 2, a local maximum) and x=1x = 1 (f=−2f = -2, a local minimum).

Solution
3x2−3=0  ⇒  x2=1  ⇒  x=±1f(−1)=−1+3=2,f(1)=1−3=−2f′ changes from + to − at −1 (top of a hill) and from − to + at 1 (bottom of a valley).\begin{aligned} &3x^2 - 3 = 0 \;\Rightarrow\; x^2 = 1 \;\Rightarrow\; x = \pm 1 \\ &f(-1) = -1 + 3 = 2, \quad f(1) = 1 - 3 = -2 \\ &f' \text{ changes from } + \text{ to } - \text{ at } -1 \text{ (top of a hill) and from } - \text{ to } + \text{ at } 1 \text{ (bottom of a valley).} \end{aligned}

Test yourself

The derivative f′(a)f'(a) is the slope of…

  1. the secant line from 0 to aa
  2. the tangent line at x=ax = a
  3. the xx-axis
  4. the line through the origin and (a,f(a))(a, f(a))

Position is s(t)=5t2s(t) = 5t^2. What is the velocity at t=2t = 2?

  1. 10
  2. 20
  3. 40
  4. 5

Why can't you make hh as small as possible in a numerical derivative?

  1. Because hh must be an integer
  2. Because the limit does not exist
  3. Because floating-point rounding error grows when subtracting nearly equal numbers
  4. Because computers cannot divide by small numbers