Basic rules
Calculate slopes, use the chain rule and distinguish derivatives from partial derivatives.
THE IDEA
Three rules cover every polynomial
Computing a limit for every function would be exhausting. Instead we compute a few once and combine them.
- Constant: a constant never changes, so its slope is 0. d/dx 7 = 0.
- Power rule: d/dx xn = n·xn−1. Bring the exponent down, then lower it by one. So x² gives 2x, x³ gives 3x² and x (which is x¹) gives 1.
- Constant multiple and sum: d/dx (c·f) = c·f′ and d/dx (f + g) = f′ + g′. Differentiate term by term.
Together: d/dx (3x² + 2x + 5) = 3·2x + 2·1 + 0 = 6x + 2, the answer to the quiz question.
See a function and its derivative together
The blue curve is f. The orange curve is f′: its height at x is the slope of the blue curve at x. Change the coefficients and probe different x. Notice three habits: where blue is flat, orange crosses zero. Where blue rises, orange is above zero. Where blue falls, orange is below. And adding a constant lifts blue without changing orange at all.
The orange dot rides at height f′(x) above or below the blue dot. Where the blue curve is flat the orange dot sits on the axis.
Predict first. What is the derivative of f(x) = x³ + 4x − 9?
Match the slope to the graph
Reading a derivative graph is a skill of its own. For each blue curve choose the orange graph that shows its slope. Think about where the blue curve rises, falls and flattens before you click.
f(x) = x² (blue). Which orange graph is f′?
f(x) = x³ (blue). Which orange graph is f′?
f(x) = 3x + 1 (blue). Which orange graph is f′?
f(x) = x² − 2x (blue). Which orange graph is f′?
0 of 0 answered correctly.
Common mistake: confusing f with f′
A derivative is a new function. Its value is a slope, not a height. The check below compares the power rule with a numerical slope:
f = lambda x: x ** 3
h = 1e-5
print((f(2 + h) - f(2 - h)) / (2 * h))
print(3 * 2 ** 2, 2 ** 2)
# output:
12.00000000021184
12 4
Chapter context
A derivative measures a local rate of change. It describes what a function does under a very small input change, rather than its average behavior over an arbitrary interval. This local sensitivity is what training algorithms use.
TRY IT YOURSELF
Part 1. Do it on the graph
Move the controls. Each task ticks from the real numbers on the screen and stays ticked once earned.
Use the sliders to build f(x) = c₃x³ + c₂x² + c₁x + c₀. The orange curve is f′.
The orange dot rides at height f′(x) above or below the blue dot. Where the blue curve is flat the orange dot sits on the axis.
- To do: Build an f whose derivative is 6x + 2
- To do: Make f nonzero everywhere (f is a constant other than 0) with a derivative that is 0 for every x
- To do: Use a real cubic (c₃ is not 0) with f(0) = 2 and f′(1) = 3
Part 2. Do it in code
- A polynomial is a list of coefficients, lowest power first: [5, 2, 3] means 5 + 2x + 3x². Write eval_poly(c, x), deriv_poly(c), poly_add(p, q) and poly_scale(s, p).
- deriv_poly applies the power rule term by term (coefficient i times i goes to position i - 1). The derivative of a constant is [0]. Do not change the input list.
- The tests also check the sum rule and the constant-multiple rule using your functions, and compare against a numerical slope.
Stuck, or something not working? You can come back to it any time.
CHECK YOUR UNDERSTANDING
Differentiate 3x squared plus 2x.
Chapter reference: math, worked example & code
This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.
Math and notation
For numerical checking, use and report a tolerance.
Worked example
Let f(x)=(3x+1)^2. At x=2, the inner value is 7, its derivative is 3, and the outer derivative is 14. Multiplying gives 42. A central difference with h=0.00001 gives approximately the same answer, within numerical error.
Reference code
The following example uses the Python standard library and does not call a remote service.
from math import isclose
f = lambda x: (3*x + 1)**2
x, h = 2, 1e-5
analytic = 6*(3*x + 1)
numeric = (f(x+h)-f(x-h))/(2*h)
assert analytic == 42
assert isclose(numeric, analytic, rel_tol=1e-7)
Python examples are provided for study and local execution; this page does not execute Python.
Common mistakes
A function value is not its derivative. The chain rule multiplies sensitivities, not intermediate values. At a corner such as abs(x) at zero, a two-sided derivative does not exist.