# Chain Rule

*The Derivative tells us the slope of a function at any point.*

There are **rules** we can follow to find many derivatives.

For example:

- The slope of a
**constant**value (like 3) is always 0 - The slope of a
**line**like 2x is 2, or 3x is 3 etc - and so on.

If we know the rate of change for two related things, how do we work out the overall rate of change?

The Chain Rule tells us how!

**6 times faster**than me.

Let's use some notation. Call the dog "y", me "x" and you can be "u":

- \frac{dy}{dx} is Sage's speed relative to me
- \frac{dy}{du} is Sage's speed relative to you
- \frac{du}{dx} is your speed relative to me

Then:

\frac{dy}{dx} = \frac{dy}{du}\frac{du}{dx}

- Sage can run 3 times faster than you, so \frac{dy}{du} = 3
- You can run 2 times faster than me, so \frac{du}{dx} = 2

\frac{dy}{dx} = \frac{dy}{du}\frac{du}{dx} = 3 × 2 = 6

But it is not usually that easy!

Because one function can depend on the current value of the other (which is itself continually changing).

### Example: What is \frac{d}{dx}sin(x^{2}) ?

There are two functions happening here, sin() and x^{2}.

But it is not sin(**x**), it is sin(**the result of x ^{2}**

^{})

Let's use "u" for **x ^{2}** so we can have:

\frac{dy}{dx} = \frac{dy}{du}\frac{du}{dx}

Which becomes:

\frac{d}{dx} sin(x^{2}) = \frac{d}{du}sin(u)\frac{d}{dx}x^{2}

The individual derivatives are:

- \frac{d}{du}sin(u) = cos(u)
- \frac{d}{dx}x
^{2}= 2x

So:

\frac{d}{dx} sin(x^{2}) = cos(u) (2x)

Substitute back u = x^{2}:

\frac{d}{dx} sin(x^{2}) = cos(x^{2}) (2x)

Which is neater this way:

\frac{d}{dx} sin(x^{2}) = 2x cos(x^{2})

### Notations

There are several different notations that can be used!

Notation | Chain Rule | |
---|---|---|

Using \frac{d}{dx} | \frac{dy}{dx} = \frac{dy}{du}\frac{du}{dx} | |

Using ’ (meaning derivative of) |
f(g(x)) = f’(g(x))g’(x) | |

As "Composition of Functions" | f º g = (f’ º g) × g’ |

Let's do the previous example again using **f(g(x)) = f'(g(x))g'(x)**:

### Example: What is \frac{d}{dx}sin(x^{2}) ?

**sin(x ^{2})** is made up of

**sin()**and

**x**:

^{2}- f(g) = sin(g)
- g(x) = x
^{2}

The Chain Rule says:

the derivative of f(g(x)) = f'(g(x))g'(x)

The individual derivatives are:

- f'(g) = cos(g)
- g'(x) = 2x

So:

\frac{d}{dx}sin(x^{2}) = cos(g(x)) (2x)

= 2x cos(x^{2})

Same result as before (thank goodness!)

Another couple of examples:

### Example: What is \frac{d}{dx}(1/cos(x)) ?

**1/cos(x)** is made up of **1/g** and **cos()**:

- f(g) = 1/g
- g(x) = cos(x)

The Chain Rule says:

the derivative of f(g(x)) = f’(g(x))g’(x)

The individual derivatives are:

- f'(g) = −1/(g
^{2}) - g'(x) = −sin(x)

So:

(1/cos(x))’ = \frac{−1}{g(x)^{2}}(−sin(x))

**= \frac{sin(x)}{cos^{2}(x)}**

Note: \frac{sin(x)}{cos^{2}(x)} is also \frac{tan(x)}{cos(x)} or many other forms.

### Example: What is \frac{d}{dx}(5x−2)^{3} ?

The Chain Rule says:

the derivative of f(g(x)) = f’(g(x))g’(x)

**(5x−2) ^{3}** is made up of

**g**and

^{3}**5x−2**:

- f(g) = g
^{3} - g(x) = 5x−2

The individual derivatives are:

- f'(g) = 3g
^{2}(by the Power Rule) - g'(x) = 5

So:

\frac{d}{dx}(5x−2)^{3} = (3g(x)^{2})(5)

= 15(5x−2)^{2}