Skip to main content
Back to module
Calculus & Linear Algebra for STEM · Derivatives

Derivative rules

Reading44mLesson 2 of 3 in this module

Differentiate polynomials, products and nested functions with the power, product and chain rules.

Why this matters

Estimating a derivative numerically works, but a formula is faster, exact and tells you more. If a cost model is C(q) = 0.02q³ − 3q² + 200q, you want C′(q), the marginal cost, as a formula you can reason about, not a table of estimates. A handful of rules covers nearly every function you will meet at work.

Notation

The derivative of f is written f′(x) or df/dx. Read df/dx as "the small change in f per small change in x". Both mean the same thing: the slope of f at x.

The core rules

RuleFormulaExample
Constant(c)′ = 0(7)′ = 0
Power(xⁿ)′ = n·xⁿ⁻¹(x⁵)′ = 5x⁴
Constant multiple(c·f)′ = c·f′(3x²)′ = 6x
Sum(f + g)′ = f′ + g′(x² + x)′ = 2x + 1
Product(f·g)′ = f′·g + f·g′see below
Chain(f(g(x)))′ = f′(g(x))·g′(x)see below

A few standard derivatives are worth memorising: (eˣ)′ = eˣ, (ln x)′ = 1/x, (sin x)′ = cos x, (cos x)′ = −sin x.

Polynomials: power rule plus sum rule

Differentiate term by term. Each term a·xⁿ becomes n·a·xⁿ⁻¹:

f(x)  = 4x³ − 5x² + 2x − 9
f′(x) = 12x² − 10x + 2

The constant −9 disappears because a constant does not change. The marginal cost from the opening example is C′(q) = 0.06q² − 6q + 200.

A polynomial is easy to handle in code as a list of coefficients, lowest power first. 4x³ − 5x² + 2x − 9 is [-9, 2, -5, 4]: the coefficient at index k belongs to xᵏ. The power rule then says: the new coefficient at index k − 1 is k times the old one at index k.

The product rule

For a product, you cannot just multiply the two derivatives. Take f(x) = x²·(3x + 1):

u = x²       u′ = 2x
v = 3x + 1   v′ = 3
f′ = u′·v + u·v′ = 2x(3x + 1) + x²·3 = 9x² + 2x

Check by expanding first: f(x) = 3x³ + x², so f′(x) = 9x² + 2x. Same answer. Multiplying the derivatives (2x · 3 = 6x) would have been wrong.

The chain rule

Use it for a function inside a function, such as f(x) = (2x + 1)⁵. Differentiate the outside, keep the inside, then multiply by the derivative of the inside:

outer: u⁵ → 5u⁴
inner: u = 2x + 1 → u′ = 2
f′(x) = 5(2x + 1)⁴ · 2 = 10(2x + 1)⁴

The chain rule is everywhere in applied work. Exponential decay e^(−kt) has derivative −k·e^(−kt). Training a neural network (backpropagation) is the chain rule applied through many layers.

Checking your work with code

A quick numerical check catches most algebra slips:

def f(x):
    return (2 * x + 1) ** 5

def f_prime(x):
    return 10 * (2 * x + 1) ** 4

h = 1e-5
x = 0.3
estimate = (f(x + h) - f(x - h)) / (2 * h)
print(estimate, f_prime(x))   # the two numbers should agree closely

Libraries such as SymPy (symbolic algebra) can also differentiate formulas for you. Knowing the rules means you can read and sanity-check what they return.

Common mistakes

  • Forgetting to lower the power. (x³)′ is 3x², not 3x³.
  • Multiplying derivatives for a product. (f·g)′ is f′g + fg′, never f′·g′.
  • Dropping the inner derivative in the chain rule. ((3x)²)′ = 2(3x)·3 = 18x, not 6x.
  • Keeping constants. The derivative of a plain number is 0.

Quick recap

  • Power rule: bring the exponent down and subtract one.
  • Differentiate sums term by term; constants vanish.
  • Products need the product rule; nested functions need the chain rule.
  • A central-difference check in code is a cheap way to confirm a hand derivation.

Try it

In the Do tab, write the power rule for a polynomial stored as a coefficient list, then watch the code confirm the product rule.

Also in this lesson: