## Differentiation primer

23 April 2019

1. Simple case: $x^a$

$\frac{d}{dx} (x^a) = a x^{a-1}$

For each term in $x$ we can multiply the term by the index of $x$ then subtract $1$ from the index of $x$.

By way of example: $\frac{d}{dx} (3x^2 - 5x) = 6x - 5$

2. Simple case: $\sin x$ and $\cos x$

$\sin x$ and $\cos x$, where $x$ is a small angle in radians:

$\frac{d}{dx}(\sin kx) = k \cos kx \\ \frac{d}{dx}(\cos kx) = - k \sin kx$

Note: need to always use radians when differentiating trigonometric functions.

There are also small angle approximations:
$\sin x \approx x \\ \cos x \approx 1 - \frac 1 2 x^2 \\ \tan x \approx x$

3. Simple case: exponentials and logarithms

The definition of $e^x$ is that the graph of the gradient is the same as the graph of $y = e^x$; $\frac{d}{dx}(e^x) = e^x$

$\frac{d}{dx}(e^{kx}) = ke^{kx} \\ \frac{d}{dx}(\ln (x^a)) = \frac a x \\ \frac{d}{dx}(a ^{kx}) = a ^{kx} k \ln a$

where $k$ is a real constant and $a \gt 0$

4. Chain rule

The chain rule is used to differentiate composite functions i.e. a function of a function.

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

where $y$ is a function of $u$, and $u$ is a function of $x$

In general:

If $y = (f(x))^n$ then $\frac{dy}{dx} = n(f(x))^{n-1} f'(x)$

If $y = f(g(x))$ then $\frac{dy}{dx} = f'(g(x)) g'(x)$

By way of example, to differentiate $y = (3x^2 - 5x)^3$:

$\text{Let } u = 3x^2 - 5x \implies \frac{du}{dx} = 6x - 5 \\ y = u^3 \implies \frac{dy}{du} = 3u^2 \\ \frac{dy}{dx} = \frac{dy}{du} \times \frac{du}{dx} \implies \frac{dy}{dx} = 3u^2 \times (6x - 5) \\ = 3(3x^2 - 5x)^2 (6x - 5)$

5. Product rule

Used for the product of two functions

If $y = uv$ then $\frac{dy}{dx} = u \frac{dv}{dx} + v \frac{du}{dx}$ where $u$ and $v$ are both functions of $x$

e.g. $y = x^2 (3x + 1)$

$\text{Let } u = x^2 \implies \frac{du}{dx} = 2x \\ \text{Let } v = (3x + 1) \implies \frac{dv}{dx} = 3$

$\frac{dy}{dx} = u \frac{dv}{dx} + v \frac{du}{dx} = x^2 (3) + (3x + 1) 2x \\ = 3x^2 + 2x(3x + 1) \\ = 3x^2 + 6x^2 + 2x = 9x^2 + 2x = x(9x + 2)$

6. Quotient rule

If $y = \frac u v$ then $\frac{dy}{dx} = \frac{1}{v^2} ( v \frac{du}{dx} - u \frac{dv}{dx} )$
where $u$ and $v$ are functions of $x$

Or in function notation:
If $f(x) = \frac{g(x)}{h(x)}$ then $f'(x) = \frac{1}{(h(x))^2} ( h(x) g'(x) - g(x) h'(x))$

By way of example:

$y = \tan x = \frac{\sin x}{\cos x} = \frac u v \\ \frac{dy}{dx} = \frac{1}{v^2} ( v \frac{du}{dx} - u \frac{dv}{dx} ) \\ u = \sin x \implies \frac{du}{dx} = \cos x \\ v = \cos x \implies \frac{dv}{dx} = - \sin x \\ \frac{dy}{dx} = \frac{1}{\cos^2 x} \times ( (\cos x) (\cos x) - (\sin x) (- \sin x) ) \\ = \frac{\cos^2 x + \sin^2 x}{\cos^2 x} = \frac{1}{\cos^2 x} = \sec^2 x$

Generalising; $\frac{d}{dx} (\tan kx) = k \sec^2 kx$

Using the quotient rule and differentiating $\sin x$ and $\cos x$ we can derive:

$\frac{d}{dx} ( \tan kx ) = k \sec ^2 kx \\ \frac{d}{dx} ( \csc kx ) = -k \csc kx \cot kx \\ \frac{d}{dx} ( \sec kx ) = k \sec kx \tan kx \\ \frac{d}{dx} ( \cot kx ) = -k \csc^2 kx$

$\frac{dy}{dx} = 1 / \frac{dx}{dy}$ can be used to differentiate the inverse of the trigonometric functions e.g. $\arcsin x$

By way of example for $\arcsin x$

$\text{Let } y = \arcsin x \\ \text{So } x = \sin y \\ \frac{dx}{dy} = \cos y \implies \frac{dy}{dx} = \frac{1}{\cos y} \\ \text{Using } \sin^2 y + \cos^2 y \equiv 1 \\ \cos^2 y = 1 - \sin^2 y \\ \cos y = \sqrt{1 - \sin^2 y} = \frac{1}{\sqrt{1 - x^2}}$

$\frac{d}{dx} (\arcsin x) = \frac 1 {\sqrt{1-x^2}}$ $\frac{d}{dx} (\arccos x) = - \frac 1 {\sqrt{1-x^2}}$ $\frac{d}{dx} (\arctan x) = \frac 1 {1+x^2}$

7. Parametric differentiation

If $x$ and $y$ are both given as functions of a parameter $t$ then $\frac{dy}{dx} = \frac{dy}{dt} / \frac{dx}{dt} = \frac{dy}{dt} \times \frac{dt}{dx}$

8. Implicit differentiation

Implicit differentiation allows for differentiation to happen more easily when it is difficult to algebraicly manipulate the function you are trying differentiate into the usual $y = \dots$ form.

There are two useful results to bear in mind for implicit differentiation:

1. $\frac{d}{dx}(y^n) = ny^{(n-1)} \frac{dy}{dx}$
2. $\frac{d}{dx}(xy) = x \frac{dy}{dx} + y$

The first means you can treat $y$ just as you would $x$, and then include (multiply by) $\frac{dy}{dx}$. All the $\frac{dy}{dx}$ terms can then be collected on one side to be left with the usual $\frac{dy}{dx} = \dots$

The second can be verified by the use of the product rule, using $xy$ for $uv$.

By way of example:

$e^{2x} + e^{2y} = xy \text{ (1)}$

Using the product rule for $\frac{d}{dx}(xy)$:
$\frac{d}{dx} (uv) = v \frac{du}{dx} + u \frac{dv}{dx} \\ \text{Let } u = x \implies \frac{du}{dx} = 1 \\ \text{Let } v = y \implies \frac{dv}{dx} = 1 \frac{dy}{dx} \\ \text{So } \frac{d}{dx} (xy) = y + x \frac{dy}{dx}$

Differentiating (1) with regard to $x$:
$2e^{2x} + 2e^{2y} \frac{dy}{dx} = y + x \frac{dy}{dx} \\ \implies 2e^{2x} - y = x \frac{dy}{dx} - 2e^{2y} \frac{dy}{dx} = (x - 2e^{2y}) \frac{dy}{dx} \\ \implies \frac{dy}{dx} = \frac{2e^{2x}-y}{x-2e^{2y}}$

Appendix — things to remember

1. If you need to take logs of both sides, use $\ln$ as this can be differentiated into $\frac 1 x$