AI Hints
Statistics & Math for ML · Lesson 92 of 138

Derivatives

Slope at a point.

⏱ 2 min read▶ Video at 1:49:12🎓 Free
Watch this lesson in the Statistics & Math for ML courseWatch on YouTube ↗Full Statistics & Math for ML course

What's the car's speed at exactly three seconds? Not between two times, but at one instant. Here's the trick. Take the average rate over a tiny interval, and make the interval smaller and smaller. The number it settles on is the derivative.

Derivatives
From the video: Derivatives
  • Speed at exactly 3 seconds?
  • Shrink the interval
  • The derivative

Shrinking the gap

We compute the average rate from three seconds to three plus H, for smaller and smaller H. Run it. As H shrinks, the answer gets closer and closer to six. So at three seconds, the car is moving at six metres per second.

derivative.pypython
def distance(t):
    return t ** 2

for h in [1, 0.1, 0.01, 0.001, 0.0001]:
    rate = (distance(3 + h) - distance(3)) / h
    print(f"h = {h:<7} rate = {rate:.4f}")
Output
h = 1       rate = 7.0000
h = 0.1     rate = 6.1000
h = 0.01    rate = 6.0100
h = 0.001   rate = 6.0010
h = 0.0001  rate = 6.0001

The tangent line

The derivative is the slope of the tangent line, the straight line that just touches the curve at that point. Here's the curve, and its tangent at three, with slope six. Run it. Near the touching point, the line and the curve are almost the same.

tangent.pypython
import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 5, 100)
plt.plot(t, t ** 2, label="distance = t²")
plt.plot(t, 9 + 6 * (t - 3), color="#22d3ee", label="tangent at t = 3")
plt.scatter([3], [9], s=80, color="#fbbf24", zorder=3)
plt.ylim(-5, 26); plt.legend(); plt.title("Slope at a point")
plt.savefig("tangent.png")

Summary

The derivative is the slope at a single point, the limit of the average rate as the interval shrinks. Next, rules that find derivatives without any limits.

Key takeaways
  • Shrink h towards 0
  • Slope of the tangent
  • f'(x)
Next up: Derivative Rules — power, sum, product