The Chain Rule

Master the chain rule to find derivatives of composite functions. Learn how to break down complex functions and apply differentiation step by step.

Intermediate

Problem statement

Given a composite function h(x) = f(g(x)), find its derivative using the chain rule.

Example

Given: h(x) = x² + 1, where g(x) = x² and f(u) = u + 1

Find: h'(x) using the chain rule

Solution: h'(x) = f'(g(x)) · g'(x) = 1 · 2x = 2x

Intuition

The chain rule handles composite functions: functions within functions. Think of it as unwrapping layers: differentiate the outer function, then multiply by the derivative of the inner function.

Key concept

If h(x) = f(g(x)), then h'(x) = f'(g(x)) · g'(x). You evaluate the outer derivative at the inner function, then multiply by the inner derivative.

For our example h(x) = x² + 1, we identify g(x) = x² (inner) and f(u) = u + 1 (outer). Then g'(x) = 2x and f'(u) = 1, so h'(x) = 1 · 2x = 2x.

Why it works

The chain rule accounts for how changes in x affect g(x), which in turn affects f(g(x)). It's the rate of change "chained" through multiple layers.

Interactive visualization

Drag the point to see how the chain rule computes the derivative of the composite function.

h(1.00) = 2.00h'(1.00) = 2.00
xy-1120246h(x) = x² + 1slope = 2.00
Inner Function
g(x) = x²
g(1.00) = 1.00
Outer Function
f(u) = u + 1
f(1.00) = 2.00
Chain Rule Calculation
h'(x) = f'(g(x)) · g'(x)
1.00 × 2.00 = 2.00
Result
h'(x) = 2x
h'(1.00) = 2.00

Chain Rule: For h(x) = f(g(x)), the derivative is h'(x) = f'(g(x)) · g'(x). Drag the point to see how the outer function derivative f'(g(x)) = 1 multiplies with the inner derivative g'(x) = 2x.

Implementation

Python
import numpy as np
import matplotlib.pyplot as plt

def chain_rule_derivative(f, g, f_prime, g_prime, x):
    """
    Calculate derivative using chain rule: (f∘g)'(x) = f'(g(x)) · g'(x)
    
    Args:
        f: Outer function
        g: Inner function
        f_prime: Derivative of outer function
        g_prime: Derivative of inner function
        x: Point at which to evaluate
    
    Returns:
        Derivative of composite function at x
    """
    # Evaluate g(x)
    g_x = g(x)
    
    # Apply chain rule: f'(g(x)) · g'(x)
    derivative = f_prime(g_x) * g_prime(x)
    
    return derivative

# Example: h(x) = (x² + 1)
# Let g(x) = x² and f(u) = u + 1
# Then h(x) = f(g(x)) = x² + 1

# Define functions
g = lambda x: x**2        # Inner function
f = lambda u: u + 1       # Outer function
h = lambda x: f(g(x))     # Composite function

# Define derivatives
g_prime = lambda x: 2*x   # g'(x) = 2x
f_prime = lambda u: 1     # f'(u) = 1

# Calculate derivative at x = 2
x_point = 2
h_prime = chain_rule_derivative(f, g, f_prime, g_prime, x_point)
print(f"h'({x_point}) = {h_prime}")  # Output: 4

# Verify: h(x) = x² + 1, so h'(x) = 2x
# At x = 2: h'(2) = 2(2) = 4 ✓

Common applications

Polynomial compositions

h(x) = (x² + 3x)⁵

h'(x) = 5(x² + 3x)⁴ · (2x + 3)

Trigonometric functions

h(x) = sin(x²)

h'(x) = cos(x²) · 2x

Exponential functions

h(x) = ex²

h'(x) = ex² · 2x

Logarithmic functions

h(x) = ln(x² + 1)

h'(x) = 2x / (x² + 1)

Related topics

Product Rule

Coming soon

Derivatives of products of functions

Implicit Differentiation

Coming soon

Chain rule with implicit functions

Related Rates

Coming soon

Apply the chain rule to real-world problems

Discussion

Questions, ideas or a different approach? Join the conversation.