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.
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.
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
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) = e^(x²)
h'(x) = e^(x²) · 2x
Logarithmic Functions
h(x) = ln(x² + 1)
h'(x) = 2x/(x² + 1)
Related Topics
Basic Derivatives
Review fundamental derivative rules
Product RuleComing Soon
Derivatives of products of functions
Implicit DifferentiationComing Soon
Chain rule with implicit functions
Related RatesComing Soon
Apply chain rule to real-world problems