# Chain rule – examples

Required math: derivatives, trig functions, chain rule, product rule

Required physics: none

Here are a few examples of using the chain rule for derivatives. The general form of the chain rule is:

 $\displaystyle \frac{df(g(x))}{dx}$ $\displaystyle =$ $\displaystyle \frac{df}{dg}\frac{dg}{dx} \ \ \ \ \ (1)$

Example 1. The chain rule applies when we need the derivative of a ‘function of a function’, as in ${f(u)}$ where ${u=g(x)}$, so for the first example, we will make it explicit which is the first function and which is the second.

First (outer) function: ${f(u)=6u-9}$. Second (inner) function: ${u=g(x)=\frac{1}{2}x^{4}}$.

First take the derivative of the outer function with respect to its variable ${u}$:

 $\displaystyle \frac{df(u)}{du}$ $\displaystyle =$ $\displaystyle \frac{d}{du}(6u-9)\ \ \ \ \ (2)$ $\displaystyle$ $\displaystyle =$ $\displaystyle 6 \ \ \ \ \ (3)$

Now take the derivative of the inner function with respect to ${x}$:

 $\displaystyle \frac{dg(x)}{dx}$ $\displaystyle =$ $\displaystyle \frac{d}{dx}\left(\frac{1}{2}x^{4}\right)\ \ \ \ \ (4)$ $\displaystyle$ $\displaystyle =$ $\displaystyle \frac{1}{2}\times4x^{3}\ \ \ \ \ (5)$ $\displaystyle$ $\displaystyle =$ $\displaystyle 2x^{3} \ \ \ \ \ (6)$

Finally, multiply the two together:

 $\displaystyle \frac{df(g(x))}{dx}$ $\displaystyle =$ $\displaystyle \frac{df}{dg}\frac{dg}{dx}\ \ \ \ \ (7)$ $\displaystyle$ $\displaystyle =$ $\displaystyle (6)(2x^{3})\ \ \ \ \ (8)$ $\displaystyle$ $\displaystyle =$ $\displaystyle 12x^{3} \ \ \ \ \ (9)$

This example could have been done by substituting ${u=g(x)}$ before doing the derivative and in that case the chain rule isn’t needed. That is we could have said

 $\displaystyle f(u)$ $\displaystyle =$ $\displaystyle f(g(x))\ \ \ \ \ (10)$ $\displaystyle$ $\displaystyle =$ $\displaystyle 6g(x)-9\ \ \ \ \ (11)$ $\displaystyle$ $\displaystyle =$ $\displaystyle 6\left(\frac{1}{2}x^{4}\right)-9\ \ \ \ \ (12)$ $\displaystyle$ $\displaystyle =$ $\displaystyle 3x^{4}-9 \ \ \ \ \ (13)$

We could then have taken the derivative directly to get ${f'(x)=12x^{3}}$. The next example will illustrate a case where the chain rule must be used.

Example 2. First function: ${f(u)=\sin u}$; Second function: ${u=g(x)=3x+1}$ (so, effectively, ${f(g(x))=\sin(3x+1)}$).

First, the outer derivative:

 $\displaystyle \frac{df(u)}{du}$ $\displaystyle =$ $\displaystyle \frac{d}{du}\sin u\ \ \ \ \ (14)$ $\displaystyle$ $\displaystyle =$ $\displaystyle \cos u \ \ \ \ \ (15)$

Then, the inner derivative:

 $\displaystyle \frac{dg(x)}{dx}$ $\displaystyle =$ $\displaystyle \frac{d}{dx}(3x+1)\ \ \ \ \ (16)$ $\displaystyle$ $\displaystyle =$ $\displaystyle 3 \ \ \ \ \ (17)$

Then, the combination

 $\displaystyle \frac{df(g(x))}{dx}$ $\displaystyle =$ $\displaystyle \frac{df}{dg}\frac{dg}{dx}\ \ \ \ \ (18)$ $\displaystyle$ $\displaystyle =$ $\displaystyle (\cos u)(3)\ \ \ \ \ (19)$ $\displaystyle$ $\displaystyle =$ $\displaystyle 3\cos(3x+1) \ \ \ \ \ (20)$

Notice in the last step, we substituted for ${u}$ in terms of ${x}$.

Example 3. The quotient rule is often stated as a separate rule for finding the derivative of the quotient of two functions, such as ${f(x)/g(x)}$. However, it is easily derived from the chain and product rules, as we’ll see here.

We can rewrite the quotient as a product:

$\displaystyle \frac{f(x)}{g(x)}=[f(x)][g(x)]^{-1} \ \ \ \ \ (21)$

We can now use the product rule to get

 $\displaystyle \frac{d}{dx}\left(\frac{f(x)}{g(x)}\right)$ $\displaystyle =$ $\displaystyle \frac{df(x)}{dx}[g(x)]^{-1}+f(x)\frac{d}{dx}[g(x)]^{-1}\ \ \ \ \ (22)$ $\displaystyle$ $\displaystyle =$ $\displaystyle \frac{f'(x)}{g(x)}+f(x)\frac{d}{dx}[g(x)]^{-1} \ \ \ \ \ (23)$

We now need to use the chain rule to find the last derivative in the above formula. If we define ${u=g(x)}$, then

 $\displaystyle \frac{d}{dx}[g(x)]^{-1}$ $\displaystyle =$ $\displaystyle \frac{d}{dx}(u^{-1})\ \ \ \ \ (24)$ $\displaystyle$ $\displaystyle =$ $\displaystyle (-1)(u^{-2})\frac{du}{dx}\ \ \ \ \ (25)$ $\displaystyle$ $\displaystyle =$ $\displaystyle -\frac{g'(x)}{g^{2}(x)} \ \ \ \ \ (26)$

where again we have replaced ${u}$ by ${g(x)}$ in the last line, just to get everything back in terms of ${x}$. We can now combine this result with the earlier one from the product rule to get:

 $\displaystyle \frac{d}{dx}\left(\frac{f(x)}{g(x)}\right)$ $\displaystyle =$ $\displaystyle \frac{f'(x)}{g(x)}-f(x)\frac{g'(x)}{g^{2}(x)}\ \ \ \ \ (27)$ $\displaystyle$ $\displaystyle =$ $\displaystyle \frac{f'(x)g(x)-f(x)g'(x)}{g^{2}(x)} \ \ \ \ \ (28)$

which is the quotient rule.

Example 4. Find the derivative of ${f(x)=(\sin x)/x^{2}}$. This is a quotient, but rather than use the quotient rule directly, we will treat it as a product and use the procedure from example 3 to find the derivative using the product and chain rules.

 $\displaystyle \frac{df}{dx}$ $\displaystyle =$ $\displaystyle \frac{d}{dx}[(\sin x)(x^{-2})]\ \ \ \ \ (29)$ $\displaystyle$ $\displaystyle =$ $\displaystyle \left(\frac{d}{dx}(\sin x)\right)(x^{-2})+\sin x\frac{d}{dx}(x^{-2})\ \ \ \ \ (30)$ $\displaystyle$ $\displaystyle =$ $\displaystyle (\cos x)(x^{-2})+(\sin x)(-2x^{-3})\ \ \ \ \ (31)$ $\displaystyle$ $\displaystyle =$ $\displaystyle \frac{\cos x}{x^{2}}-\frac{2\sin x}{x^{3}}\ \ \ \ \ (32)$ $\displaystyle$ $\displaystyle =$ $\displaystyle \frac{x\cos x-2\sin x}{x^{3}} \ \ \ \ \ (33)$

A good exercise for the reader is to check this result by using the quotient rule at the end of Example 3 directly and show you get the same answer.

Example 5. Find the derivative of ${f(x)=\sin(\cos^{2}(x^{3}+4x))}$. This is a four-level nested function, so we’ll need to use the chain rule several times. We can write this function as ${f(x)=\sin(g(h(j(x)))}$ with ${g(h)=h^{2}}$, ${h(j)=\cos j}$ and ${j(x)=x^{3}+4x}$. (You should take the time to write this out and verify that these substitutions work before proceeding.)

The chain rule can now be applied in the form

 $\displaystyle \frac{df}{dx}$ $\displaystyle =$ $\displaystyle \frac{df}{dg}\frac{dg}{dh}\frac{dh}{dj}\frac{dj}{dx} \ \ \ \ \ (34)$

Seen broken down like this, the problem becomes much easier, since we need to work out four standard derivatives:

 $\displaystyle \frac{df}{dg}$ $\displaystyle =$ $\displaystyle \cos g\ \ \ \ \ (35)$ $\displaystyle \frac{dg}{dh}$ $\displaystyle =$ $\displaystyle 2h\ \ \ \ \ (36)$ $\displaystyle \frac{dh}{dj}$ $\displaystyle =$ $\displaystyle -\sin j\ \ \ \ \ (37)$ $\displaystyle \frac{dj}{dx}$ $\displaystyle =$ $\displaystyle 3x^{2}+4 \ \ \ \ \ (38)$

Combining all these, we get

 $\displaystyle \frac{df}{dx}$ $\displaystyle =$ $\displaystyle (\cos g)(2h)(-\sin j)(3x^{2}+4)\ \ \ \ \ (39)$ $\displaystyle$ $\displaystyle =$ $\displaystyle (\cos g)(2h)(-\sin(x^{3}+4))(3x^{2}+4)\ \ \ \ \ (40)$ $\displaystyle$ $\displaystyle =$ $\displaystyle (\cos g)(2\cos j)(-\sin(x^{3}+4))(3x^{2}+4)\ \ \ \ \ (41)$ $\displaystyle$ $\displaystyle =$ $\displaystyle (\cos g)(2\cos(x^{3}+4))(-\sin(x^{3}+4))(3x^{2}+4)\ \ \ \ \ (42)$ $\displaystyle$ $\displaystyle =$ $\displaystyle (\cos h^{2})(2\cos(x^{3}+4))(-\sin(x^{3}+4))(3x^{2}+4)\ \ \ \ \ (43)$ $\displaystyle$ $\displaystyle =$ $\displaystyle (\cos(\cos^{2}(j))(2\cos(x^{3}+4))(-\sin(x^{3}+4))(3x^{2}+4)\ \ \ \ \ (44)$ $\displaystyle$ $\displaystyle =$ $\displaystyle (\cos(\cos^{2}((x^{3}+4)))(2\cos(x^{3}+4))(-\sin(x^{3}+4))(3x^{2}+4)\ \ \ \ \ (45)$ $\displaystyle$ $\displaystyle =$ $\displaystyle -2\cos(\cos^{2}((x^{3}+4))\cos(x^{3}+4)\sin(x^{3}+4)(3x^{2}+4) \ \ \ \ \ (46)$

Here, in the first line, we’ve just plugged in the derivatives as calculated above. Then in each succeeding line, we have worked backwards through the functions to put everything in terms of ${x}$. The last line just rearranges a couple of things to make it neater.

The final result is complex, but there are no tricks involved; we just apply the chain rule in the normal way.