The chain rule

We can now differentiate $\sin x$ and $x^2+1$. But what about $\sin(x^2+1)$? Or $(x^3-4x)^5$? These are composite functions: one function is inside another. The chain rule tells us how to differentiate them.

The chain rule is one of the most used rules in calculus.

Composite functions

A composite function puts the output of one function into another function (see composite functions). We write

$(f\circ g)(x)=f(g(x))$.

Here $g$ is the inner function, and $f$ is the outer function. To evaluate $f(g(x))$, we first find $g(x)$. Then we put that value into $f$.

For example, in $y=(x^3-4x)^5$:

In $y=\sin(x^2+1)$, the inner function is $u=x^2+1$, and the outer function is $y=\sin u$.

The idea: rates multiply

Suppose $y$ changes $3$ times as fast as $u$. And $u$ changes $2$ times as fast as $x$. Then $y$ changes $3\cdot 2=6$ times as fast as $x$.

Think of three gears. The first gear turns the second, and the second turns the third. If each step doubles the speed, the last gear turns $2\cdot 2=4$ times as fast as the first.

A derivative is a rate of change. So the derivative of a composite function is a product of two rates:

$\dfrac{dy}{dx}=\dfrac{dy}{du}\cdot\dfrac{du}{dx}$.

The chain rule

If $g$ is differentiable at $x$, and $f$ is differentiable at $g(x)$, then

$\dfrac{d}{dx}f(g(x))=f'(g(x))\cdot g'(x)$.

In words: the derivative of the outer function, with the inner function left inside, times the derivative of the inner function.

With $y=f(u)$ and $u=g(x)$, the same rule in Leibniz notation is

$\dfrac{dy}{dx}=\dfrac{dy}{du}\cdot\dfrac{du}{dx}$.

The Leibniz form is easy to remember. It looks as if the $du$'s cancel. They are not really fractions, but the form still helps.

Optional Why the chain rule works

Let $x$ change by a small amount $\Delta x$. Then $u$ changes by some amount $\Delta u$, and $y$ changes by some amount $\Delta y$. ($\Delta$ means "change in.") By the definition of the derivative,

$\begin{align*}&\dfrac{dy}{dx}\\&=\lim_{\Delta x\to 0}\dfrac{\Delta y}{\Delta x}\end{align*}$

If $\Delta u\ne 0$, multiply and divide by $\Delta u$:

$\begin{align*}&=\lim_{\Delta x\to 0}\left(\dfrac{\Delta y}{\Delta u}\cdot\dfrac{\Delta u}{\Delta x}\right)\end{align*}$

Now let $\Delta x\to 0$. Since $g$ is differentiable, it is continuous, so $\Delta u\to 0$ too. Then

  • ${\dfrac{\Delta u}{\Delta x}\to\dfrac{du}{dx}}$
  • ${\dfrac{\Delta y}{\Delta u}\to\dfrac{dy}{du}}$

So

$\begin{align*}&\dfrac{dy}{dx}=\dfrac{dy}{du}\cdot\dfrac{du}{dx}\end{align*}$

This argument fails if $\Delta u=0$ for small $\Delta x$ (for example, when $g$ is constant near $x$). A full proof handles that case too. The rule is still true.

How to use the chain rule

  1. Find the inner function $u$ and the outer function.
  2. Differentiate the outer function. Leave the inner function inside, unchanged.
  3. Multiply by the derivative of the inner function.

Example 1: Find $f'(x)$ for

$f(x)=(2x+1)^2$.

Solution:

Inner function: $u=2x+1$, so $u'=2$.

Outer function: $u^2$, with derivative $2u$.

$\begin{align*}&f'(x)\\&=2(2x+1)\cdot 2\\&=8x+4\end{align*}$

In basic differentiation rules (Example 5), we expanded first and got the same answer.

A common mistake: forgetting the last factor, $2$. The answer $2(2x+1)$ is wrong.

Example 2: Find $\dfrac{dy}{dx}$ for $y=(x^3-4x)^5$.

Solution:

Let $u=x^3-4x$. Then $y=u^5$.

$\dfrac{dy}{du}=5u^4$   and   $\dfrac{du}{dx}=3x^2-4$

Multiply, and then replace $u$ by $x^3-4x$:

$\begin{align*}&\dfrac{dy}{dx}\\&=5u^4(3x^2-4)\\&=5(x^3-4x)^4(3x^2-4)\end{align*}$

Expanding $(x^3-4x)^5$ first would take much longer.

The general power rule

Example 2 shows a pattern. When the outer function is a power, the chain rule gives

$\dfrac{d}{dx}(u^n)=nu^{n-1}\cdot u'$,

where $u$ is a function of $x$. This is called the general power rule.

Example 3: Let $f(x)=\sqrt{x^2+9}$.

(a) Find $f'(x)$.

(b) Find the equation of the tangent line at $x=4$.

Solution:

(a) Rewrite the root as a power:

$f(x)=(x^2+9)^{1/2}$

Inner function: $u=x^2+9$, so $u'=2x$.

$\begin{align*}&f'(x)\\&=\tfrac{1}{2}(x^2+9)^{-1/2}\cdot 2x\\&=\dfrac{x}{\sqrt{x^2+9}}\end{align*}$

(b) The point: $f(4)=\sqrt{16+9}=5$. So the point is $(4,5)$.

The slope: $f'(4)=\dfrac{4}{\sqrt{25}}=\dfrac{4}{5}$.

The tangent line:

$\begin{align*}y-5&=\tfrac{4}{5}(x-4)\\y&=\tfrac{4}{5}x+\tfrac{9}{5}\end{align*}$

Example 4: Find $y'$ for

$y=\dfrac{1}{(3x-1)^2}$.

Solution:

Rewrite the fraction as a power:

$y=(3x-1)^{-2}$

Inner function: $u=3x-1$, so $u'=3$.

$\begin{align*}&y'\\&=-2(3x-1)^{-3}\cdot 3\\&=-\dfrac{6}{(3x-1)^3}\end{align*}$

The quotient rule also works here, but the general power rule is faster.

The chain rule with trigonometric functions

When the outer function is sine, cosine, or tangent, the chain rule gives

$\dfrac{d}{dx}(\sin u)=\cos u\cdot u'$

$\dfrac{d}{dx}(\cos u)=-\sin u\cdot u'$

$\dfrac{d}{dx}(\tan u)=\sec^2 u\cdot u'$

As in derivatives of trigonometric functions, all angles are in radians.

Example 5: Find each derivative.

(a) $y=\sin 3x$

(b) $y=\cos(x^2)$

(c) $y=\sin^2 x$

Solution:

(a) Inner function: $u=3x$, so $u'=3$.

$y'=\cos 3x\cdot 3=3\cos 3x$

(b) Inner function: $u=x^2$, so $u'=2x$.

$y'=-\sin(x^2)\cdot 2x=-2x\sin(x^2)$

(c) Here $\sin^2 x$ means $(\sin x)^2$. So the outer function is a square.

Inner function: $u=\sin x$, so $u'=\cos x$.

$y'=2\sin x\cdot\cos x=2\sin x\cos x$

Compare (b) and (c). In $\cos(x^2)$, we square $x$ first and then take the cosine. In $\sin^2 x$, we take the sine first and then square. The inner and outer functions are different, so the derivatives are different.

Combining the chain rule with other rules

Many functions need more than one rule. Work from the outside in. Ask: what is the last step in computing this function?

Example 6: Find $y'$ for

$y=x(2x+3)^4$.

Solution:

The last step is multiplying two factors. So start with the product rule. The first factor is $x$, with derivative $1$:

$\begin{align*}&y'\\&=1\cdot(2x+3)^4+x\cdot\dfrac{d}{dx}(2x+3)^4\end{align*}$

Use the chain rule on $(2x+3)^4$. The inner function $2x+3$ has derivative $2$:

$\begin{align*}&=(2x+3)^4+x\cdot 4(2x+3)^3\cdot 2\\&=(2x+3)^4+8x(2x+3)^3\end{align*}$

Factor out the common factor $(2x+3)^3$:

$\begin{align*}&=(2x+3)^3[(2x+3)+8x]\end{align*}$

Simplify inside the brackets:

$\begin{align*}&y'=(2x+3)^3(10x+3)\end{align*}$

Example 7: Find $y'$ for

$y=\sin^3(2x)$.

Solution:

Here $\sin^3(2x)$ means $[\sin(2x)]^3$. This function has three layers:

  • Outside: a cube, $(\ \ )^3$.
  • Middle: sine.
  • Inside: $2x$.

Use the chain rule twice. Differentiate each layer from the outside in, and multiply:

$\begin{align*}&y'\\&=3\sin^2(2x)\cdot\cos(2x)\cdot 2\\&=6\sin^2(2x)\cos(2x)\end{align*}$

Using values of $f$ and $g$

Example 8: Suppose that

$g(1)=3$,   $g'(1)=2$,

$f(3)=7$,   $f'(3)=5$.

Let $h(x)=f(g(x))$. Find $h'(1)$.

Solution:

By the chain rule,

$h'(x)=f'(g(x))\cdot g'(x)$.

At $x=1$:

$\begin{align*}&h'(1)\\&=f'(g(1))\cdot g'(1)\\&=f'(3)\cdot 2\\&=5\cdot 2\\&=10\end{align*}$

Notice that we need $f'$ at $g(1)=3$, not at $1$. The value $f(3)=7$ is not needed.

Summary

Here $u$ is a differentiable function of $x$, and $u'=\dfrac{du}{dx}$:

RuleFormula
Chain rule$\dfrac{d}{dx}f(g(x))=f'(g(x))\,g'(x)$
Leibniz form$\dfrac{dy}{dx}=\dfrac{dy}{du}\cdot\dfrac{du}{dx}$
General power rule$\dfrac{d}{dx}(u^n)=nu^{n-1}\,u'$
Sine$\dfrac{d}{dx}(\sin u)=\cos u\cdot u'$
Cosine$\dfrac{d}{dx}(\cos u)=-\sin u\cdot u'$
Tangent$\dfrac{d}{dx}(\tan u)=\sec^2 u\cdot u'$