Skip to contentSkip to lesson map

Chain Rule I

Status
Updates coming
Reading
MMAC Ch 4.5, pp 425-431
Lesson map

Objectives

  1. Given two functions, find the specified composition; recognize that order matters.
  2. Given a composition, identify the inside and outside functions.
  3. Use the chain rule to find the derivative of a composition by hand.

1. Composition of Functions

Objective. Given two functions, find the specified composition; recognize that order matters.

Definition 1 (Composition).

If f(x)f(x) and g(x)g(x) are functions, then the composition of ff with gg is f∘g(x)=f[g(x)]f \circ g(x) = f[g(x)] when this expression is defined.

Definition 2 (Inside and outside functions).

In the composition f∘gf \circ g, the function gg is the inside function. The function ff is the outside function.

The inside function is applied first, to the input xx. The outside function is applied to the output of gg. The brackets in f[g(x)]f[g(x)] mark evaluation: f[g(x)]f[g(x)] means ff evaluated at g(x)g(x), the same as f(g(x))f(g(x)).

For f(x)=ln⁡(x)f(x) = \ln(x) and g(x)=−1−x2g(x) = -1 - x^2, the expression f[g(x)]=ln⁡(−1−x2)f[g(x)] = \ln(-1 - x^2) is undefined at every input, because every output g(x)g(x) is at most −1-1 and ln⁡\ln is defined only for positive inputs. The expression fails the condition in the definition of composition that f[g(x)]f[g(x)] be defined.

The product x2sin⁡(x)x^2\sin(x) is not the composition of x2x^2 and sin⁡(x)\sin(x) in either order. Its last step multiplies the outputs of the two functions instead of applying one function to the output of the other. The product has no inside function and no outside function.

To find f∘g(x)f \circ g(x), replace every xx in the formula for ff with the whole formula for g(x)g(x), in parentheses.

Example 1

For

f(x)=x3,g(x)=x+1, f(x) = x^3, \qquad g(x) = x + 1,

find f∘g(x)f \circ g(x) and g∘f(x)g \circ f(x), and evaluate both at x=−2x = -2.

ShowHide solution

By the definition of composition, f∘g(x)=f[g(x)]f \circ g(x) = f[g(x)]. For f∘gf \circ g, replace xx in the formula for ff with x+1x + 1, then evaluate at x=−2x = -2:

f∘g(x)=f[x+1]=(x+1)3,f∘g(−2)=(−2+1)3=(−1)3=−1. f \circ g(x) = f[x + 1] = (x + 1)^3, \qquad f \circ g(-2) = (-2 + 1)^3 = (-1)^3 = -1.

For g∘fg \circ f, replace xx in the formula for gg with x3x^3, then evaluate at x=−2x = -2:

g∘f(x)=g[x3]=x3+1,g∘f(−2)=(−2)3+1=−8+1=−7. g \circ f(x) = g[x^3] = x^3 + 1, \qquad g \circ f(-2) = (-2)^3 + 1 = -8 + 1 = -7.

In the diagram, the input −2-2 passes through both compositions. In f∘gf \circ g the inside function gg is applied first and sends −2-2 to −1-1. In g∘fg \circ f the inside function ff is applied first and sends −2-2 to −8-8.

Figure

Order of composition. The compositions f∘gf \circ g and g∘fg \circ f are different functions when their outputs differ at some input, as at x=−2x = -2 in Example 1. The two can agree at one input and still be different functions. At x=0x = 0 in Example 1, both compositions equal 1:

f∘g(0)=(0+1)3=1,g∘f(0)=03+1=1. f \circ g(0) = (0 + 1)^3 = 1, \qquad g \circ f(0) = 0^3 + 1 = 1.

For some pairs the two orders give the same function. For p(x)=x+2p(x) = x + 2 and q(x)=x+5q(x) = x + 5,

p∘q(x)=(x+5)+2=x+7,q∘p(x)=(x+2)+5=x+7. p \circ q(x) = (x + 5) + 2 = x + 7, \qquad q \circ p(x) = (x + 2) + 5 = x + 7.

Example 2

For

f(x)=x2,g(x)=sin⁡(x), f(x) = x^2, \qquad g(x) = \sin(x),

find f∘g(x)f \circ g(x) and g∘f(x)g \circ f(x).

ShowHide solution

Replacing xx in the formula for each outside function with the formula for the inside function gives

f∘g(x)=f[sin⁡(x)]=(sin⁡(x))2,g∘f(x)=g[x2]=sin⁡(x2). f \circ g(x) = f[\sin(x)] = (\sin(x))^2, \qquad g \circ f(x) = g[x^2] = \sin(x^2).

The two compositions are different functions, because the graph of (sin⁡(x))2(\sin(x))^2 stays between 0 and 1 while the graph of sin⁡(x2)\sin(x^2) runs from −1-1 to 1. At x=2x = 2, for example, (sin⁡(2))2≈0.827(\sin(2))^2 \approx 0.827 and sin⁡(22)=sin⁡(4)≈−0.757\sin(2^2) = \sin(4) \approx -0.757.

Figure

Example 3

For

f(x)=cos⁡(3x+1),g(x)=ex−x, f(x) = \cos(3x + 1), \qquad g(x) = e^x - x,

find f∘g(x)f \circ g(x), g∘f(x)g \circ f(x), and f(x)g(x)f(x)g(x).

ShowHide solution

For f∘gf \circ g, replace each xx in ff with ex−xe^x - x and distribute the 3:

f∘g(x)=cos⁡(3(ex−x)+1)=cos⁡(3ex−3x+1). f \circ g(x) = \cos\bigl(3(e^x - x) + 1\bigr) = \cos(3e^x - 3x + 1).

For g∘fg \circ f, replace each xx in gg with cos⁡(3x+1)\cos(3x + 1):

g∘f(x)=ecos⁡(3x+1)−cos⁡(3x+1). g \circ f(x) = e^{\cos(3x + 1)} - \cos(3x + 1).

For the product, multiply the two outputs instead of applying one function to the other:

f(x)g(x)=cos⁡(3x+1)(ex−x). f(x)g(x) = \cos(3x + 1)(e^x - x).

Lesson map

2. Inside and Outside Functions

Objective. Given a composition, identify the inside and outside functions.

Decomposing a composition.

  1. Find the last function applied in computing the composition. Pass over a constant added, subtracted, multiplied, or divided at the very end, and keep that constant in the outside function. A constant divided by a power counts as a power in a denominator.
  2. Find the row of the table for that function, and read the inside function g(x)g(x) from it.
  3. Replace g(x)g(x) with xx in the composition to get the outside function f(x)f(x).
Outside functionWhere g(x)g(x) sitsComposition and g(x)g(x)
Trigonometric or logarithmicin the parentheses after the function namecos⁡(5x−2)\cos(5x - 2), g(x)=5x−2g(x) = 5x - 2
Exponentialin the exponent2sin⁡(x)2^{\sin(x)}, g(x)=sin⁡(x)g(x) = \sin(x)
Power or root, including a power in a denominatorin the base of the power or under the root4+x3\sqrt{4 + x^3}, g(x)=4+x3g(x) = 4 + x^3

In the table’s rows, step 3 gives the outside functions cos⁡(x)\cos(x), 2x2^x, and x\sqrt{x}.

Example 4

Identify the inside function g(x)g(x) and the outside function f(x)f(x) of each composition:

(x2−3)5,ex2+3x+1,sin⁡(x2)+1. (x^2 - 3)^5, \qquad e^{x^2 + 3x + 1}, \qquad \sin(x^2) + 1.
ShowHide solution

By the definition of inside and outside functions (section 1), the inside function gg is applied to xx first, and the outside function ff is applied to the output of gg.

  • In (x2−3)5(x^2 - 3)^5, the last function applied is a power, and by the power row g(x)g(x) is the base. The inside function is g(x)=x2−3g(x) = x^2 - 3 and the outside function is f(x)=x5f(x) = x^5.
  • In ex2+3x+1e^{x^2 + 3x + 1}, the last function applied is an exponential, and by the exponential row g(x)g(x) is the exponent. The inside function is g(x)=x2+3x+1g(x) = x^2 + 3x + 1 and the outside function is f(x)=exf(x) = e^x.
  • In sin⁡(x2)+1\sin(x^2) + 1, the last function applied before adding 1 is a sine, and by the trigonometric row g(x)g(x) is in the parentheses. The inside function is g(x)=x2g(x) = x^2 and the outside function is f(x)=sin⁡(x)+1f(x) = \sin(x) + 1.

In the last item, the choice g(x)=sin⁡(x2)g(x) = \sin(x^2) with f(x)=x+1f(x) = x + 1 is also correct, because f[g(x)]=sin⁡(x2)+1f[g(x)] = \sin(x^2) + 1. With that choice, gg is itself a composition, and the chain rule of section 3 is applied a second time to find g′(x)g'(x).

Products, quotients, sums, and differences. Let the last step of a function combine the outputs of two functions of xx, neither of them a constant. The function is a product when the last step multiplies, a quotient when it divides, and a sum or difference when it adds or subtracts. Differentiate a product with the product rule and a quotient with the quotient rule (Lesson 30), and a sum or difference term by term. A factor or a term that is itself a composition is differentiated with the chain rule of section 3, as the term cos⁡(x2)\cos(x^2) is in x3+cos⁡(x2)x^3 + \cos(x^2).

Example 5

For each function, identify the inside and outside functions, or state that the function is a product, a quotient, or a sum:

(x2+3)cos⁡(x),5ex3−x,1(x2+1)3,ex+x3. (x^2 + 3)\cos(x), \qquad 5e^{x^3 - x}, \qquad \frac{1}{(x^2 + 1)^3}, \qquad e^x + x^3.
ShowHide solution
  • The function (x2+3)cos⁡(x)(x^2 + 3)\cos(x) is a product, because its last step multiplies the outputs of two functions of xx. Differentiate it with the product rule.
  • In 5ex3−x5e^{x^3 - x}, the inside function is g(x)=x3−xg(x) = x^3 - x and the outside function is f(x)=5exf(x) = 5e^x. The constant 5, multiplied at the last step, stays in the outside function.
  • The function 1(x2+1)3\dfrac{1}{(x^2 + 1)^3} is the constant 1 divided by a power, which counts as a power in a denominator, the last row of the table. Its inside function is g(x)=x2+1g(x) = x^2 + 1 and its outside function is f(x)=1x3=x−3f(x) = \dfrac{1}{x^3} = x^{-3}.
  • The function ex+x3e^x + x^3 is a sum, because its last step adds the outputs of two functions of xx. Differentiate it term by term.

Lesson map

3. The Chain Rule

Objective. Use the chain rule to find the derivative of a composition by hand.

Rule 3 (Chain rule).

Let f(x)f(x) and g(x)g(x) be differentiable functions. When the compositions are defined,

ddx[f(g(x))]=f′[g(x)]⋅g′(x). \frac{d}{dx}\bigl[f(g(x))\bigr] = f'[g(x)] \cdot g'(x).

The chain rule in words. The derivative of a composition is the derivative of the outside function ff, evaluated at the inside function g(x)g(x), times the derivative of the inside function.

Applying the chain rule.

  1. Name the inside function g(x)g(x) and the outside function f(x)f(x).
  2. Differentiate each one: g′(x)g'(x) and f′(x)f'(x).
  3. Evaluate f′f' at the inside function: f′[g(x)]f'[g(x)].
  4. Multiply f′[g(x)]f'[g(x)] by g′(x)g'(x).

Each row of the table is the chain rule applied to one basic outside function. In the table, nn is a constant and aa is a constant with a>0a > 0. The power row is true at each xx where gg is differentiable and [g(x)]n−1[g(x)]^{n-1} is defined, and the ln⁡\ln row at each xx where gg is differentiable and g(x)>0g(x) > 0.

Outside functionCompositionDerivative
xnx^n[g(x)]n[g(x)]^nn[g(x)]n−1⋅g′(x)n[g(x)]^{n-1}\cdot g'(x)
exe^xeg(x)e^{g(x)}eg(x)⋅g′(x)e^{g(x)}\cdot g'(x)
axa^xag(x)a^{g(x)}ln⁡(a) ag(x)⋅g′(x)\ln(a)\,a^{g(x)}\cdot g'(x)
ln⁡(x)\ln(x)ln⁡(g(x))\ln(g(x))1g(x)⋅g′(x)\dfrac{1}{g(x)}\cdot g'(x)
sin⁡(x)\sin(x)sin⁡(g(x))\sin(g(x))cos⁡(g(x))⋅g′(x)\cos(g(x))\cdot g'(x)
cos⁡(x)\cos(x)cos⁡(g(x))\cos(g(x))−sin⁡(g(x))⋅g′(x)-\sin(g(x))\cdot g'(x)

The two factors of the chain rule. The derivative of sin⁡(x2)\sin(x^2) is cos⁡(x2)⋅2x\cos(x^2)\cdot 2x. The inside function x2x^2 stays unchanged in the cosine, and the derivative 2x2x of the inside function multiplies the cosine as the factor g′(x)g'(x).

Example 6

Find the derivative by hand:

h(x)=(x2−3)5. h(x) = (x^2 - 3)^5.
ShowHide solution

The function hh is the composition f∘gf \circ g of the functions named below. By the chain rule, h′(x)=f′[g(x)]⋅g′(x)h'(x) = f'[g(x)] \cdot g'(x). Name the inside and outside functions and their derivatives:

g(x)=x2−3,g′(x)=2x,f(x)=x5,f′(x)=5x4. g(x) = x^2 - 3, \quad g'(x) = 2x, \qquad f(x) = x^5, \quad f'(x) = 5x^4.

Evaluate f′f' at the inside function:

f′[g(x)]=5(x2−3)4. f'[g(x)] = 5(x^2 - 3)^4.

Multiply f′[g(x)]f'[g(x)] by g′(x)g'(x):

h′(x)=5(x2−3)4⋅2x=10x(x2−3)4. h'(x) = 5(x^2 - 3)^4 \cdot 2x = 10x(x^2 - 3)^4.

Example 7

Find the derivative by hand:

h(x)=ln⁡(18−x3). h(x) = \ln(18 - x^3).
ShowHide solution

The inside function is g(x)=18−x3g(x) = 18 - x^3, with g′(x)=−3x2g'(x) = -3x^2. The outside function is f(x)=ln⁡(x)f(x) = \ln(x), with f′(x)=1xf'(x) = \frac{1}{x}. Substitute into the chain rule:

h′(x)=118−x3⋅(−3x2)=−3x218−x3. h'(x) = \frac{1}{18 - x^3}\cdot(-3x^2) = \frac{-3x^2}{18 - x^3}.

Example 8

Find the derivative by hand:

h(x)=4ex2−9x. h(x) = 4e^{x^2 - 9x}.
ShowHide solution

The inside function is g(x)=x2−9xg(x) = x^2 - 9x, with g′(x)=2x−9g'(x) = 2x - 9. The outside function is f(x)=4exf(x) = 4e^x, with f′(x)=4exf'(x) = 4e^x. Substitute into the chain rule and distribute the 4:

h′(x)=4ex2−9x⋅(2x−9)=(8x−36)ex2−9x. h'(x) = 4e^{x^2 - 9x}\cdot(2x - 9) = (8x - 36)e^{x^2 - 9x}.

Example 9

Find the derivative by hand:

h(x)=37x+cos⁡(x). h(x) = 3^{7x + \cos(x)}.
ShowHide solution

The inside function is g(x)=7x+cos⁡(x)g(x) = 7x + \cos(x), with g′(x)=7−sin⁡(x)g'(x) = 7 - \sin(x). The outside function is f(x)=3xf(x) = 3^x, with f′(x)=ln⁡(3) 3xf'(x) = \ln(3)\,3^x. Substitute into the chain rule:

h′(x)=ln⁡(3) 37x+cos⁡(x)(7−sin⁡(x)). h'(x) = \ln(3)\,3^{7x + \cos(x)}\bigl(7 - \sin(x)\bigr).

Example 10

Find the derivative by hand:

h(x)=cos⁡(2ln⁡(x)−1x). h(x) = \cos\Bigl(2\ln(x) - \frac{1}{x}\Bigr).
ShowHide solution

Rewrite 1x\frac{1}{x} as x−1x^{-1}. The inside function is g(x)=2ln⁡(x)−x−1g(x) = 2\ln(x) - x^{-1}. Differentiate the first term by the rule for ln⁡(x)\ln(x) and the second term by the power rule:

g′(x)=2x+x−2=2x+1x2. g'(x) = \frac{2}{x} + x^{-2} = \frac{2}{x} + \frac{1}{x^2}.

The outside function is f(x)=cos⁡(x)f(x) = \cos(x), with f′(x)=−sin⁡(x)f'(x) = -\sin(x). Substitute into the chain rule:

h′(x)=−sin⁡(2ln⁡(x)−1x)(2x+1x2). h'(x) = -\sin\Bigl(2\ln(x) - \frac{1}{x}\Bigr)\Bigl(\frac{2}{x} + \frac{1}{x^2}\Bigr).

Example 11

Find the slope of the tangent line to the graph of

h(x)=x2+9 h(x) = \sqrt{x^2 + 9}

at x=4x = 4.

ShowHide solution

The slope of the tangent line at x=4x = 4 is h′(4)h'(4). Find h′(x)h'(x) by the chain rule, then evaluate it at x=4x = 4. Rewrite the root as a power, h(x)=(x2+9)1/2h(x) = (x^2 + 9)^{1/2}. The inside function is g(x)=x2+9g(x) = x^2 + 9, with g′(x)=2xg'(x) = 2x. The outside function is f(x)=x1/2f(x) = x^{1/2}, with f′(x)=12x−1/2f'(x) = \tfrac{1}{2}x^{-1/2} by the power rule. Substitute into the chain rule:

h′(x)=12(x2+9)−1/2⋅2x=xx2+9. h'(x) = \tfrac{1}{2}(x^2 + 9)^{-1/2}\cdot 2x = \frac{x}{\sqrt{x^2 + 9}}.

Evaluate the derivative at x=4x = 4:

h′(4)=442+9=425=45=0.8. h'(4) = \frac{4}{\sqrt{4^2 + 9}} = \frac{4}{\sqrt{25}} = \frac{4}{5} = 0.8.

The tangent line passes through the point (4,h(4))=(4,42+9)=(4,5)\bigl(4, h(4)\bigr) = \bigl(4, \sqrt{4^2 + 9}\bigr) = (4, 5) on the graph, and it rises 0.8 units for each unit of xx.

Figure

Checking in R. To check a hand derivative, evaluate it and the derivative function that D() returns (Lesson 30 section 3) at the same input. Compare values instead of formulas, because the formula that D() prints can look different from the hand derivative. A different value shows an error in the hand work or the R entry. Equal values support the hand derivative, and a check at a second input makes a chance agreement of two different functions unlikely. For Example 6, the hand derivative gives

h′(2)=10(2)(22−3)4=20(1)4=20,h′(1)=10(1)(12−3)4=10(16)=160, h'(2) = 10(2)\bigl(2^2 - 3\bigr)^4 = 20(1)^4 = 20, \qquad h'(1) = 10(1)\bigl(1^2 - 3\bigr)^4 = 10(16) = 160,

and D() gives the same values:

> dh = D((x^2 - 3)^5 ~ x)
> dh(2)
[1] 20
> dh(1)
[1] 160

Lesson map

Found a mistake, a broken tool or something unclear? Report a problem