The Chain Rule for Differentiation

The chain rule allows us to differentiate composite functions.
In essence, when we differentiate using the chain rule we are making a change of variable, or a substitution.
The idea being to write the function in terms of another variable, typically called \(u(x)\), such that it drastically simplifies differentiating the function.
By the end of this section we'll know how to differentiate functions like either of the following: \[f(x) = sin \begin{pmatrix} x^2 + 1 \end{pmatrix}\] \[y = e^{cos(x)}\] \[f(x) = ln \begin{pmatrix}3x+1 \end{pmatrix}\] To do this we start by learning the formula for the chain rule, we then view some tutorials to learn how to use the formula and why it works. FInally we'll work our way through several worked examples to consolidate what we've seen.

Formula - Chain Rule

Formula 1

Given a composite function \[\text{if} \quad f(x) = g \begin{bmatrix} h(x) \end{bmatrix} \] \[\text{then} \quad f'(x) = h'(x)\times g' \begin{bmatrix} h(x) \end{bmatrix} \]

Formula 2

Another way of writing this \[\text{if} \quad y = f \begin{bmatrix} u(x) \end{bmatrix}\] \[\text{then} \quad \frac{dy}{dx} = \frac{dy}{du}.\frac{du}{dx}\]

Tutorial 1

Before working through some exercises, we recommend watching Tutorial 2, in which we learn more about the chain rule and gain inisght into how it works.
Spend the time to watch this as it should help develop a much better sense of what we're actually doing when we use the chain rule.

If you'd prefer to try the exercises right away, by all means do so but do make sure to watch Tutorial 2 afterwards.

Exercise 1

  1. Differentiate the function defined as \(f(x) = sin\begin{pmatrix} x^3-2 \end{pmatrix}\).

  2. Given \(y = \sqrt{3x^2-4x+7}\), find an expression for \(\frac{dy}{dx}\).

  3. Differentiate the function \(f(x) = \begin{pmatrix} x^2 + 3 \end{pmatrix}^7\).

  4. Find \(\frac{dy}{dx}\), given \(y = e^{3x^2-1}\).

  5. Differentiate the function \(f(x) = ln \begin{pmatrix} x^2 + x \end{pmatrix}\).

  6. Given \(y = cos \begin{pmatrix} 2x + 1 \end{pmatrix}\), find \(\frac{dy}{dx}\).

Answers Without Working

  1. \(f'(x) = 3x^2.cos \begin{pmatrix} x^3 - 2 \end{pmatrix}\)

  2. \(\frac{dy}{dx} = \frac{3x-2}{\sqrt{3x^2 - 4x + 7}}\)

  3. \(f'(x) = 14x \begin{pmatrix} x^2 + 3 \end{pmatrix}^6\)

  4. \( \frac{dy}{dx} = 6x.e^{3x^2-1}\)

  5. \(f'(x) = \frac{2x+1}{x^2+x}\)

  6. \(\frac{dy}{dx} = -2.sin \begin{pmatrix} 2x + 1 \end{pmatrix}\)

Answers With Working

  1. The function \(f(x) = sin \begin{pmatrix} x^3 - 2 \end{pmatrix}\) can be written \(f(x) = g \begin{bmatrix} h(x) \end{bmatrix}\), where: \[g(x) = sin(x) \quad \text{and} \quad h(x) = x^3 - 2\] and \[g'(x) = cos(x) \quad \text{and} \quad h'(x) = 3x^2\] We can now use the chain rule to write: \[f'(x) = h'(x) \times g'\begin{bmatrix} h(x) \end{bmatrix}\] That's: \[f'(x) = 3x^2.cos \begin{pmatrix} x^3-2\end{pmatrix}\]

  2. We can differentiate \(y = \sqrt{3x^2 - 4x + 7}\) as follows:

    Let \(u(x) = 3x^2 - 4x + 7 \), then: \[y = \sqrt{u}\] \[\frac{dy}{du} = \frac{1}{2\sqrt{u}}\] and \[\frac{du}{dx} = 6x - 4 \] and using the chain rule we can write: \[\begin{aligned} \frac{dy}{dx} & = \frac{dy}{du}.\frac{dy}{dx} \\ & = \frac{1}{2\sqrt{u}}. \begin{pmatrix} 6x - 4 \end{pmatrix} \\ & = \frac{6x - 4}{2\sqrt{u}} \\ & = \frac{2 \begin{pmatrix} 3x - 2 \end{pmatrix}}{2\sqrt{u}} \\ & = \frac{3x - 2}{\sqrt{u}}\\ \frac{dy}{dx} &= \frac{3x-2}{\sqrt{3x^2 - 4x + 7}} \end{aligned}\]

  3. The function \(f(x) = \begin{pmatrix} x^2 + 3 \end{pmatrix}^7\) can be written \(f(x) = g \begin{bmatrix} h(x) \end{bmatrix}\) where \[g(x) = x^7 \quad \text{and} \quad h(x) = x^2 + 3 \] and \[g'(x) = 7x^6 \quad \text{and} \quad h'(x) = 2x \] So, using the chain rule, we find the derivative as follows: \[\begin{aligned} f'(x) & = h'(x) \times g' \begin{bmatrix} h(x) \end{bmatrix} \\ & = 2x \times 7 \begin{pmatrix} x^2 + 3 \end{pmatrix}^6 \\ f'(x) & = 14x \begin{pmatrix} x^2 + 3 \end{pmatrix}^6 \end{aligned}\]

  4. We differentiate \(y = e^{3x^2-1}\) as follows:

    Let \[u(x) = 3x^2 - 1\] then \[y = e^u\] \[\frac{dy}{du} = e^u\] and \[\frac{du}{dx} = 6x\] Now, using the chain rule, we find the derivative: \[\begin{aligned} \frac{dy}{dx} & = \frac{dy}{du}.\frac{du}{dx} \\ & = e^u.6x \\ \frac{dy}{dx} & = 6x.e^{3x^2-1} \end{aligned}\]

  5. The function \(f(x) = ln \begin{pmatrix} x^2 + x \end{pmatrix}\) can be written \(f(x) = g \begin{bmatrix} h(x) \end{bmatrix}\) where: \[g(x) = ln(x) \quad \text{and} \quad h(x) = x^2 + x\] and \[g'(x) = \frac{1}{x} \quad \text{and} \quad h'(x) = 2x+1\] We now use the chain rule to find the derivative: \[\begin{aligned} f'(x) &= h'(x)\times g' \begin{bmatrix} h(x) \end{bmatrix} \\ & = \begin{pmatrix} 2x+1 \end{pmatrix} \times \frac{1}{x^2+x} \\ f'(x) & = \frac{2x+1}{x^2+x} \end{aligned}\]

  6. We differentiate \(y = cos \begin{pmatrix} 2x + 1 \end{pmatrix}\) as follows:

    Let \[u(x) = 2x+1\] Then \[y = cos(u)\] \[\frac{dy}{du} = -sin(u)\] and \[\frac{du}{dx} = 2\] Now using the chain rule we can differentiate as follows: \[\begin{aligned} \frac{dy}{dx} &= \frac{dy}{du}.\frac{du}{dx} \\ & = -sin(u). 2\\ & = -2.sin(u) \\ \frac{dy}{dx} &= -2 sin \begin{pmatrix} 2x + 1 \end{pmatrix} \end{aligned}\]

Some Special Cases

We now learn a "special case" of the chain rule.
If a function is a composition of a function \(g(x)\) and a linear function \(ax+b\), like \(y = \sqrt{6x+10}\), then the chain rule reduces to a simple formula, which is definitely worth memorizing.
We start by learning the formula and then work through some examples.

Special Case 1

If a function is composed of a function \(g(x)\) and a linear function \(ax+b\), \(f(x) = g \begin{pmatrix} ax+b \end{pmatrix}\) then the chain rule will always lead to the following result: \[\text{if} \quad f(x) = g \begin{pmatrix} ax + b \end{pmatrix}\] \[\text{then} \quad f'(x) = a\times g' \begin{pmatrix} ax + b \end{pmatrix}\]

This special case of the chain rule is further explained and illustrated in Tutorial 3.
Spend a few minutes to watch it now.

Exercise 2

Differentiate each of the following:

  1. \(f(x) = \begin{pmatrix} 5x - 2 \end{pmatrix}^9\)

  2. \(y = sin \begin{pmatrix} 3x - 9 \end{pmatrix}\)

  3. \(f(x) = e^{-2x+1}\)

  4. \(y = \sqrt{4x + 5}\)

  5. \(f(x) = 3.tan \begin{pmatrix} 4x \end{pmatrix}\)

Answers Without Working

  1. \(f'(x) = 45 \begin{pmatrix} 5x - 2 \end{pmatrix}^8\)

  2. \(\frac{dy}{dx} = 3cos \begin{pmatrix} 3x - 9 \end{pmatrix}\)

  3. \(f'(x) = -2.e^{-2x+1}\)

  4. \( \frac{dy}{dx} = \frac{2}{\sqrt{4x+5}}\)

  5. \(f'(x) = 12sec^2(4x) \quad \text{or} \quad f'(x) = 12 + 12tan^2(4x)\)

Answers With Working

  1. The function \(f(x) = \begin{pmatrix} 5x - 2 \end{pmatrix}^9\) can be written \(f(x) = g \begin{pmatrix} ax + b \end{pmatrix}\), where: \[g(x) = x^9\] \[g'(x) = 9x^8\] and \[ax+b = 5x - 2\] Using the special case 1 formula we differentiate this function as follows: \[\begin{aligned} f'(x) & = a\times g'\begin{pmatrix} ax + b \end{pmatrix} \\ & = 5 \times 9 \begin{pmatrix} 5x - 2 \end{pmatrix}^8 \\ f'(x) & = 45 \begin{pmatrix} 5x - 2 \end{pmatrix}^8 \end{aligned}\]

  2. The function \(y = sin \begin{pmatrix} 3x - 9 \end{pmatrix}\) can be written \(y = g \begin{pmatrix} ax + b \end{pmatrix}\), where: \[g(x) = sin(x)\] \[g'(x) = cos(x)\] and \[ax+b = 3x - 9 \] So we can differentiate this using the special case 1 formula: \[\begin{aligned} \frac{dy}{dx} & = a\times g' \begin{pmatrix} ax + b \end{pmatrix} \\ & = 3 \times cos \begin{pmatrix} 3x - 9 \end{pmatrix} \\ \frac{dy}{dx} & = 3cos\begin{pmatrix} 3x - 9 \end{pmatrix} \end{aligned}\]

  3. We can write \(f(x) = e^{-2x +1}\) as \(f(x) = g \begin{pmatrix} ax + b \end{pmatrix}\), where: \[g(x) = e^x \] \[g'(x) = e^x \] and \[ax + b = -2x + 1\] So we can differentiate this using the special case 1 formula: \[\begin{aligned} f'(x) & = a \times g' \begin{pmatrix} ax + b \end{pmatrix} \\ & = -2 \times e^{-2x+1} \\ f'(x) &= -2e^{-2x+1} \end{aligned}\]

  4. The function \(y = \sqrt{4x + 5}\) can be written \(y = g \begin{pmatrix} ax + b \end{pmatrix}\), where: \[g(x) = \sqrt{x}\] \[g'(x) = \frac{1}{2\sqrt{x}}\] and \[ax + b = 4x + 5\] So we can differentiate this using the special case 1 formula: \[\begin{aligned} \frac{dy}{dx} & = a\times g' \begin{pmatrix} ax + b \end{pmatrix} \\ & = 4 \times \frac{1}{2 \sqrt{4x + 5 }} \\ & = \frac{4}{2 \sqrt{4x + 5}} \\ \frac{dy}{dx} &= \frac{2}{\sqrt{4x + 5 }} \end{aligned}\]

  5. The function \(f(x) = 3.tan \begin{pmatrix} 4x \end{pmatrix}\) can be written \(f(x) = 4.g \begin{pmatrix} ax + b \end{pmatrix}\), where: \[g(x) = tan(x)\] \[g'(x) = sec^2(x)\] or \[g'(x) = 1 + tan^2(x)\] and \[ax + b = 4x + 0\] So, using the special case 1 formula, there are two possible ways of writing the derivative:
    • option 1: \[\begin{aligned} f'(x) & = 3\times a\times g' \begin{pmatrix} ax + b \end{pmatrix} \\ & = 3\times 4 \times sec^2\begin{pmatrix} 4x \end{pmatrix} \\ f'(x) & = 12.sec^2 \begin{pmatrix} 4x \end{pmatrix} \end{aligned}\]

    • option 2: \[\begin{aligned} f'(x) & = 3\times a\times g' \begin{pmatrix} ax + b \end{pmatrix} \\ & = 3 \times 4 \begin{pmatrix} 1 + tan^2 \begin{pmatrix} 4x \end{pmatrix} \end{pmatrix} \\ & = 12 \begin{pmatrix} 1 + tan^2 \begin{pmatrix} 4x \end{pmatrix} \end{pmatrix}\\ f'(x) & = 12 + 12.tan^2 \begin{pmatrix} 4x \end{pmatrix} \\ \end{aligned}\]

We now look into another special case, which works each time we have to differentiate acomposite function in which the natural logarithm, \(ln(x)\), is the "outer function". For example \(f(x) = ln \begin{pmatrix} x^3+7x^2-8 \end{pmatrix}\).
Again, in this case, the chain rule leads us to a formula worth memorizing.
We start by learning the formula and then we work through a few examples.

Special Case 2

If a function is composed from the natural logarithm, \(ln(x)\), and some other function \(u(x)\) then the chain rule will always lead to the following result: \[\text{if} \quad f(x) = ln \begin{pmatrix} u(x) \end{pmatrix}\] \[\text{then} \quad f'(x) = \frac{u'(x)}{u(x)}\]

This special case of the chain rule is further explained and illustrated in Tutorial 3.
Spend a few minutes to watch it now.

Exercise 3

Differentiate each of the following:

  1. \(f(x) = ln \begin{pmatrix} x^2 - 3 \end{pmatrix} \)

  2. \(y = 3.ln \begin{pmatrix} x^3-3x^2 + 6 \end{pmatrix}\)

  3. \(f(x) = -2.ln \begin{pmatrix} 4x+ 5 \end{pmatrix}\)

  4. \(y = 4.ln \begin{pmatrix} \sqrt{x} \end{pmatrix} \)

  5. \(f(x) = ln \begin{pmatrix} \frac{1}{x} \end{pmatrix}\)

Answers Without Working

  1. \(f'(x) = \frac{2x}{x^2-3}\)

  2. \(\frac{dy}{dx} = \frac{9x^2 - 18x}{x^3 - 3x^2 + 6}\)

  3. \(f'(x) = - \frac{8}{4x+5}\)

  4. \(\frac{dy}{dx} = \frac{2}{x}\)

  5. \(f'(x) = - \frac{1}{x}\)

Answers With Working

  1. The function \(f(x) = ln \begin{pmatrix} x^2 - 3\end{pmatrix}\) can be written: \[f(x) = ln \begin{pmatrix} u(x) \end{pmatrix}\] Where \[u(x) = x^2 - 3\] and \[u'(x) = 2x\] Using the formula we saw above we can state: \[\begin{aligned} f'(x) & = \frac{u'(x)}{u(x)} \\ f'(x) & = \frac{2x}{x^2 - 3} \end{aligned}\]

  2. The function \(y = 3. ln \begin{pmatrix} x^3 - 3x^2 + 6\end{pmatrix}\) can be written: \[y = 3 ln \begin{pmatrix} u(x)\end{pmatrix}\] Where \[u(x) = x^3 - 3x^2 + 6\] and \[u'(x) = 3x^2 -6x \] Using the formula we saw above we can write: \[\begin{aligned} \frac{dy}{dx} & = 3 \times \frac{u'(x)}{u(x)} \\ & = 3 \times \frac{3x^2 -6x}{x^3 - 3x^2 + 6} \\ & = \frac{3\begin{pmatrix} 3x^2 - 6x \end{pmatrix}}{x^3 - 3x^2 + 6} \\ \frac{dy}{dx} & = \frac{ 9x^2 - 18x}{x^3 - 3x^2 + 6} \end{aligned}\]

  3. The function \(f(x) = -2 ln \begin{pmatrix} 4x+5 \end{pmatrix}\) can be written: \[f(x) = -2ln \begin{pmatrix} u(x) \end{pmatrix}\] where \[u(x) = 4x+5\] and \[u'(x) = 4\] So \[\begin{aligned} f'(x) & = -2 \times \frac{u'(x)}{u(x)} \\ & = -2 \times \frac{4}{4x+5} \\ & = - \frac{2\times 4}{4x+5} \\ f'(x) & = - \frac{-8}{4x+5} \end{aligned}\]

  4. The function \(y = 4.ln \begin{pmatrix} \sqrt{x} \end{pmatrix}\) can be written: \[ y =4.ln \begin{pmatrix} u(x) \end{pmatrix}\] Where \[u(x) = \sqrt{x}\] and \[u'(x) = \frac{1}{2 \sqrt{x}}\] So \[\begin{aligned} \frac{dy}{dx} & = 4 \times \frac{u'(x)}{u(x)} \\ & = 4 \times \frac{ \frac{1}{2\sqrt{x}}}{\sqrt{x}} \\ & = 4\times \frac{1}{2\sqrt{x}} \times \frac{1}{\sqrt{x}} \\ & = \frac{4}{2 \sqrt{x} \times \sqrt{x}} \\ & = \frac{4}{2x} \\ \frac{dy}{dx} &= \frac{2}{x} \end{aligned}\]

  5. The function \(f(x) = ln \begin{pmatrix} \frac{1}{x} \end{pmatrix}\) can be written: \[f(x) = ln \begin{pmatrix} u(x) \end{pmatrix}\] Where \[u(x) = \frac{1}{x}\] and \[u'(x) = - \frac{1}{x^2}\] So \[\begin{aligned} f'(x) & = \frac{u'(x)}{u(x)} \\ & = \frac{ - \frac{1}{x^2}}{\frac{1}{x}} \\ & = - \frac{1}{x^2}\times x \\ & = - \frac{x}{x^2} \\ f'(x) & = - \frac{1}{x} \end{aligned}\]

Special Case 3

If a function is composed of a function \(h(x)\) and a power function \(x^n\), then the chain rule leads to the following result: \[\text{if} \quad f(x) = \begin{bmatrix} h(x) \end{bmatrix}^n\] \[\text{then} \quad f'(x) = h'(x)\times n \begin{bmatrix}h(x) \end{bmatrix}^{n-1}\]

We further illustrate and explain this sepcial case in Tutorial 4.
Spend a few minutes to watch it now.

Exercise 4

Differentiate each of the following:

  1. \(f(x)=\begin{pmatrix} 4x^2-7\end{pmatrix}^5\)

  2. \(y = sin^5(x)\)

  3. \(f(x) = \begin{pmatrix}2cos(x)\end{pmatrix}^3\)

  4. \(y= \begin{bmatrix} \frac{ln(x)}{2} \end{bmatrix}^6\)

  5. \(f(x) = tan^5(x)\)

Answers Without Working

  1. \(f'(x) = 40x\begin{pmatrix}4x^2-7 \end{pmatrix}^4\)

  2. \(\frac{dy}{dx} = 5.cos(x).sin^4(x)\)

  3. \(f'(x) = -24.sin(x).cos^2(x)\)

  4. \(\frac{dy}{dx}=\frac{3.ln^5(x)}{32x}\)

  5. Two answers possible: \[f'(x)=5.sec^2(x).tan^4(x)\] or \[f'(x)=5.tan^4(x)+5tan^6(x)\]

Solution With Working

  1. We can see that \(f(x) = \begin{pmatrix} 4x^2 - 7 \end{pmatrix}^5\) can be written \(f(x)=\begin{bmatrix}h(x)\end{bmatrix}^5\), where:

    \(h(x)=4x^2-7\) and \(h'(x)=8x\)

    So using the special case 3, we can write: \[\begin{aligned} f'(x) & = h'(x)\times 5\begin{bmatrix}h(x) \end{bmatrix}^4 \\ & = 8x \times 5 \begin{bmatrix} 4x^2 - 7 \end{bmatrix}^4 \\ f'(x) & = 40x \begin{pmatrix} 4x^2 - 7 \end{pmatrix}^4 \end{aligned}\]

  2. We can see that \(y=sin^5(x)\) can be written \(y=\begin{bmatrix}h(x)\end{bmatrix}^5\), where:

    \(h(x)=sin(x)\) and \(h'(x)=cos(x)\).

    Using the special case 3 we find the derivative function: \[\begin{aligned} \frac{dy}{dx} & = h'(x)\times 5 \begin{bmatrix}h(x)\end{bmatrix}^4 \\ & = cos(x)\times 5 \begin{bmatrix} sin(x) \end{bmatrix}^4 \\ \frac{dy}{dx} & = 5.cos(x).sin^4(x) \end{aligned}\]

  3. The function \(f(x)=\begin{pmatrix}2.cos(x)\end{pmatrix}^3\) can be written \(f(x)=\begin{bmatrix}h(x)\end{bmatrix}^3\), where:

    \(h(x)=2.cos(x)\) and \(h'(x)=-2.sin(x)\).

    Using the special case 3 of the chain rule we find the derivative as follows: \[\begin{aligned} f'(x) & = h'(x)\times 3 \begin{bmatrix} h(x)\end{bmatrix}^2 \\ & = -2.sin(x)\times 3 \begin{bmatrix} 2.cos(x) \end{bmatrix}^2 \\ & = -6.sin(x) \begin{bmatrix}2.cos(x) \end{bmatrix}^2\\ & = -6.sin(x)\times 2^2.cos^2(x) \\ & = -6.sin(x)\times 4.cos^2(x)\\ f'(x) & = -24 sin(x)cos^2(x) \end{aligned}\]

  4. The function \(y = \begin{bmatrix} \frac{ln(x)}{2} \end{bmatrix}^6\) can be written \(y=\begin{bmatrix}h(x) \end{bmatrix}^6\), where:

    \(h(x) = \frac{ln(x)}{2}\) and \(h'(x)=\frac{1}{2x}\).

    Using the special case 3 of the chain rule we can now differentiate: \[\begin{aligned} \frac{dy}{dx} & = h'(x)\times 6\begin{bmatrix}h(x)\end{bmatrix}^5 \\ & = \frac{1}{2x}\times 6 \begin{bmatrix} \frac{ln(x)}{2} \end{bmatrix}^5 \\ & = \frac{6}{2x}.\begin{bmatrix} \frac{ln(x)}{2} \end{bmatrix}^5 \\ & = \frac{3}{x}.\begin{bmatrix} \frac{ln(x)}{2} \end{bmatrix}^5 \\ & = \frac{3}{x}. \frac{ln^5(x)}{2^5}\\ & = \frac{3}{x}.\frac{ln^5(x)}{32}\\ \frac{dy}{dx} & = \frac{3.ln^5(x)}{32x} \end{aligned}\]

  5. The function \(f(x) = tan^5(x)\) can be written \(f(x) = \begin{bmatrix}h(x)\end{bmatrix}^5\), where:

    \(h(x)=tan(x)\) and \(h'(x)=sec^2(x)\) or \(h'(x)=1+tan^2(x)\).

    Depending on which of the two possible expressions for \(h'(x)\) we choose we'll get one or the other of the following solutions:

    If we choose \(h'(x) = sec^2(x)\), then:

    \[\begin{aligned} f'(x) & = h'(x)\times 5 \begin{bmatrix}h(x)\end{bmatrix}^4 \\ & = sec^2(x)\times 5 \begin{bmatrix} tan(x) \end{bmatrix}^4 \\ f'(x) & = 5.sec^2(x).tan^4(x) \end{aligned}\]
    If we choose \(h'(x) = 1+tan^2(x)\), then:

    \[\begin{aligned} f'(x) & = h'(x) \times 5 \begin{bmatrix}h(x)\end{bmatrix}^4 \\ & = \begin{pmatrix}1+tan^2(x) \end{pmatrix} \times 5 \begin{bmatrix} tan(x) \end{bmatrix}^4 \\ & = 5 \begin{pmatrix}1+tan^2(x) \end{pmatrix} tan^4(x) \\ f'(x) & = 5.tan^4(x) + 5.tan^6(x) \end{aligned}\]