## MA101.21 Examples of the Chain Rule and Partial Differentiation

### Example 1

$f=f(x,y), x=r\cos{\theta}, y=r\sin{\theta}$

Find $\displaystyle \frac{\partial{^2}{f}}{\partial{r^2}}$ and $\displaystyle \frac{\partial{^2}{f}}{\partial{\theta^2}}$

$\displaystyle \frac{\partial{f}}{\partial{r}} = \frac{\partial{f}}{\partial{x}}\cdot\frac{\partial{x}}{\partial{r}}+\frac{\partial{f}}{\partial{y}}\cdot\frac{\partial{y}}{\partial{r}}=\cos{\theta}\frac{\partial{f}}{\partial{x}}+\sin{\theta}\frac{\partial{f}}{\partial{y}}$

$\displaystyle \frac{\partial{f}}{\partial{\theta}} = \frac{\partial{f}}{\partial{x}}\cdot\frac{\partial{x}}{\partial{\theta}}+\frac{\partial{f}}{\partial{y}}\cdot\frac{\partial{y}}{\partial{\theta}}=-r\sin{\theta}\frac{\partial{f}}{\partial{x}}+r\cos{\theta}\frac{\partial{f}}{\partial{y}}$

So therefore:

$\displaystyle \frac{\partial}{\partial{r}}=\cos{\theta}\frac{\partial}{\partial{x}}+\sin{\theta}\frac{\partial}{\partial{y}}$

$\displaystyle \frac{\partial}{\partial{\theta}}=-r\sin{\theta}\frac{\partial}{\partial{x}}+r\cos{\theta}\frac{\partial}{\partial{y}}$

Now,

\displaystyle \begin{aligned} \frac{\partial{^2}{f}}{\partial{\theta^2}}&=\frac{\partial}{\partial{\theta}}\Big(\frac{\partial{f}}{\partial{\theta}}\Big)\\&=\frac{\partial}{\partial{\theta}}\Big(-r\sin{\theta}\frac{\partial{f}}{\partial{x}}+\cos{\theta}\frac{\partial{f}}{\partial{y}}\Big)\\&=-r\cos{\theta}\frac{\partial{f}}{\partial{x}}-r\sin{\theta}\frac{\partial}{\partial{\theta}}\Big(\frac{\partial{f}}{\partial{x}}\Big)-r\sin{\theta}\frac{\partial{f}}{\partial{y}}+\cos{\theta}\frac{\partial}{\partial{\theta}}\Big(\frac{\partial{f}}{\partial{y}}\Big)\\&=-r\cos{\theta}\frac{\partial{f}}{\partial{x}}-r\sin{\theta}\Big(-r\sin{\theta}\frac{\partial}{\partial{x}}+r\cos{\theta}\frac{\partial}{\partial{y}}\Big)\frac{\partial{f}}{\partial{x}}-r\sin{\theta}\frac{\partial{f}}{\partial{y}}+r\cos{\theta}\Big(-r\sin{\theta}\frac{\partial}{\partial{x}}+r\cos{\theta}\frac{\partial}{\partial{y}}\Big)\frac{\partial{f}}{\partial{y}}\\&=-r\cos{\theta}\frac{\partial{f}}{\partial{x}}+r^2\sin{^2}{\theta}\frac{\partial{^2}{f}}{\partial{x^2}}-r^2\sin{\theta}\cos{\theta}\frac{\partial{^2}{f}}{\partial{y}\partial{x}}-r\sin{\theta}\frac{\partial{f}}{\partial{y}}-r^2\sin{\theta}\cos{\theta}\frac{\partial{^2}{f}}{\partial{x}\partial{y}}+r^2\cos{^2}{\theta}\frac{\partial{^2}{f}}{\partial{y^2}}\\&=r^2\sin{^2}{\theta}\frac{\partial{^2}{f}}{\partial{x^2}}-2r^2\sin{\theta}\cos{\theta}\frac{\partial{^2}{f}}{\partial{x}\partial{y}}+r^2\cos{^2}{\theta}\frac{\partial{^2}{f}}{\partial{x^2}}-r\cos{\theta}\frac{\partial{f}}{\partial{x}}-r\sin{\theta}\frac{\partial{f}}{\partial{y}} \end{aligned}

\displaystyle \begin{aligned} \frac{\partial{^2}{f}}{\partial{r^2}} &= \frac{\partial}{\partial{r}}\Big(\frac{\partial{f}}{\partial{r}}\Big)=\frac{\partial}{\partial{r}}\Big(\cos{\theta}\frac{\partial{f}}{\partial{x}}+\sin{\theta}\frac{\partial{f}}{\partial{y}}\Big)\\&=\cos{\theta}\frac{\partial}{\partial{r}}\Big(\frac{\partial{f}}{\partial{x}}\Big)+\frac{\partial{f}}{\partial{x}}\cdot 0+\sin{\theta}\frac{\partial}{\partial{r}}\Big(\frac{\partial{f}}{\partial{y}}\Big)+\frac{\partial{f}}{\partial{y}}\cdot 0\\&=\cos{\theta}\Big(\cos{\theta}\frac{\partial}{\partial{x}}+\sin{theta}\frac{\partial}{\partial{y}}\Big)\Big(\frac{\partial{f}}{\partial{x}}\Big)+\sin{\theta}\Big(\cos{\theta}\frac{\partial}{\partial{x}}+\sin{\theta}\frac{\partial}{\partial{y}}\Big)\Big(\frac{\partial{f}}{\partial{y}}\Big)\\&=\cos{^2}{\theta}\frac{\partial{^2}{f}}{\partial{x^2}}+2\cos{\theta}\sin{\theta}\frac{\partial{^2}{f}}{\partial{x}\partial{y}}+\sin{^2}{\theta}\frac{\partial{^2}{f}}{\partial{y^2}} \end{aligned}

Note:

$\displaystyle \frac{\partial{^2}{f}}{\partial{r^2}}+\frac{1}{r}\frac{\partial{f}}{\partial{r}}+\frac{1}{r^2}\frac{\partial{^2}{f}}{\partial{r^2}}=\frac{\partial{^2}{f}}{\partial{x^2}}+\frac{\partial{^2}{f}}{\partial{y^2}}$

### Example 2

$f(x,y)=\sin{x^2+y^2}, x=3t, y=\frac{1}{1+t^2}$

Find $\displaystyle \frac{df}{dt}$

We have,

\displaystyle \begin{aligned} \frac{df}{dt} &= \frac{\partial{f}}{\partial{x}}\cdot\frac{dx}{dt}+\frac{\partial{f}}{\partial{y}}\cdot\frac{dy}{dt}\\&=2x\cos{x^2+y^2}\cdot 3+2y\cos{x^2+y^2}((1-t^2)^{-2}\cdot 2t))\\&= 2\cdot3t\cdot\cos{\Big(9t^2+\frac{1}{(1+t^2)^2}\Big)}\cdot 3+2\cdot\frac{1}{1+t^2}\cos{\Big(9t^2+\frac{1}{(1+t^2)^2}\Big)}((1+t^2)^{-2}\cdot 2t \end{aligned}

## MA101.20 Generalisation of the chain rule to partials

Consider the following simple example. Let f be a function of two variables defined by:

$f(x,y)=x^2 y$ where $x,y \in \mathbb{R}$.

By substituting,

$X = u \cos{v}$
$Y = u + 3v$

Let us define a function F of two variables by $F(x,y) = u^2 \cos{^2}{v}(u + 3v)$

Then we can calculate

$\frac{\partial{F}}{\partial{u}} = 3u\cos{^2}{v}(u+2v)$

With the obvious intentions regarding the partial derivatives $\frac{\partial{f}}{\partial{x}}, \frac{\partial{x}}{\partial{u}}, \frac{\partial{x}}{\partial{u}}, \frac{\partial{y}}{\partial{u}}$ we can also calculate

\displaystyle \begin{aligned} &\frac{\partial{f}}{\partial{x}} \cdot \frac{\partial{x}}{\partial{u}}+\frac{\partial{f}}{\partial{y}} \cdot \frac{\partial{y}}{\partial{u}} \\&= 2xy\cos{v}+x^2\cdot 1 \\&= 2u\cos{v}(u+3v)\cos{u} + y^2\cos{^2}{v} \\&= 3u\cos{^2}{v}(u+2v) \\&= \frac{\partial{F}}{\partial{u}} \end{aligned}

It can also be checked that

\displaystyle \begin{aligned} &\frac{\partial{f}}{\partial{x}} \cdot \frac{\partial{x}}{\partial{v}}+\frac{\partial{f}}{\partial{y}} \cdot \frac{\partial{y}}{\partial{v}} = \frac{\partial{F}}{\partial{v}} \end{aligned}

These two results are indeed true for a general function $f(x,y)$ and substitution $x=x(u,v), y=y(u,v)$. They are regarded as a generalisation of the chain rule for one variable. Again $\frac{\partial{F}}{\partial{u}}$ and $\frac{\partial{F}}{\partial{v}}$ are often confusingly written as $\frac{\partial{f}}{\partial{u}}$ and $\frac{\partial{f}}{\partial{v}}$.

The rule is then

$\displaystyle \frac{\partial{f}}{\partial{u}} = \frac{\partial{f}}{\partial{x}} \cdot \frac{\partial{x}}{\partial{u}}+\frac{\partial{f}}{\partial{y}} \cdot \frac{\partial{y}}{\partial{u}}$

$\displaystyle \frac{\partial{f}}{\partial{v}} = \frac{\partial{f}}{\partial{x}} \cdot \frac{\partial{x}}{\partial{v}}+\frac{\partial{f}}{\partial{y}} \cdot \frac{\partial{y}}{\partial{v}}$

It is very important to remember what is meant by all these items.

Note the chain rule can be used both ways.

ie let $f(x,y)$, $x=x(u,v)$, $y=y(u,v)$ define $F(u,v)$

We have

$\displaystyle \frac{\partial{F}}{\partial{u}} = \frac{\partial{f}}{\partial{x}} \cdot \frac{\partial{x}}{\partial{u}}+\frac{\partial{f}}{\partial{y}} \cdot \frac{\partial{y}}{\partial{u}}$

But also $f(u,v)$ defines $f(x,y)$ (substituting for u and v in terms of x and y)

So,

$\displaystyle \frac{\partial{f}}{\partial{x}} = \frac{\partial{f}}{\partial{u}} \cdot \frac{\partial{u}}{\partial{x}}+\frac{\partial{f}}{\partial{v}} \cdot \frac{\partial{v}}{\partial{x}}$

and, of course, we put F as f throughout.

These results are special cases of the so called general chain rule.

If we have a function $f(x_{1},...x_{n})$ where x are substitutions

$\displaystyle x_1 = \phi (u_{1},...u_{n})$
$\displaystyle x_2 = \phi (u_{1},...u_{n})$
$\displaystyle \vdots$
$\displaystyle x_n = \phi (u_{1},...u_{n})$

Then $\displaystyle \frac{\partial{f}}{\partial{u_1}} = \frac{\partial{f}}{\partial{x_1}} \cdot \frac{\partial{x_1}}{\partial{u_1}}+ \frac{\partial{f}}{\partial{x_2}} \cdot \frac{\partial{x_2}}{\partial{u_1}}+\cdots+ \frac{\partial{f}}{\partial{x_n}} \cdot \frac{\partial{x_n}}{\partial{u_1}}$

###### Special cases

i) $\displaystyle f=f(x,y), x=x(t), y=y(t)$

$\displaystyle \frac{\partial{f}}{\partial{t}} = \frac{\partial{f}}{\partial{x}} \cdot \frac{\partial{x}}{\partial{t}}+\frac{\partial{f}}{\partial{y}} \cdot \frac{\partial{y}}{\partial{t}}$

ii) $\displaystyle f=f(x,y), y=y(x), x=x$

$\displaystyle \frac{\partial{f}}{\partial{x}} = \frac{\partial{f}}{\partial{x}} +\frac{\partial{f}}{\partial{v}} \cdot \frac{\partial{v}}{\partial{x}}$

## MA101.18 Partial Differentiation

Consider the curve in which the surface $z=f(x,y)$ meets the plane $y=c$ a constant.

In this plane $z=f(x,c)$, and $\displaystyle \frac{dz}{dx}$ would be a formula for the gradient of the tangent to the curve.

If we differentiate $f(x,y)$ with respect to x, treating the y as if it was a constant (some say holding y constant), the the derivative obtained is called the partial derivative of $f(x,y)$ with respect to x and we write $\displaystyle \frac{\partial f}{\partial x}$ or $f_x$ or $D_x f$. Similarily we have $\displaystyle \frac{\partial f}{\partial y}$.

With functions of more than two variables one differentiates with respect to one of the variables by holding all the other variables constant.

##### Examples

$\displaystyle \frac{\partial}{\partial x} (x^2 y^2 + \tan{x}) = 2xy^2 + \sec{^2}{x}$.

$\displaystyle \frac{\partial}{\partial y}( x^2 y^2 + tan x) =2x^2 y$

$\displaystyle \frac{\partial}{\partial x} (2x+\sin{xy}) = 2 + y \cos{xy}$

$\displaystyle \frac{\partial}{\partial y} (2x+\sin{xy}) = x \cos{xy}$

In the obvious way we can have higher order partial derivatives.

\displaystyle \begin{aligned} f(x,y) &= x^2 y + \sin{x} \\ \frac{\partial ^2 f}{\partial x^2} &= \frac{\partial}{\partial x}\bigg[\frac{\partial}{\partial x}(x^2y + \sin{x})\bigg] \\ &= \frac{\partial}{\partial x}\bigg[2xy+\cos{x}\bigg] \\ &= 2y - \sin{x}\end{aligned}

\displaystyle \begin{aligned} \frac{\partial ^2 f}{\partial y \partial x} &= f_{yx} \\ &= \frac{\partial}{\partial y}\bigg[\frac{\partial}{\partial x}(x^2y + \sin{x})\bigg] \\ &= 2x \end{aligned}

\displaystyle \begin{aligned} \frac{\partial ^2 f}{\partial x \partial y} &= f_{xy} \\ &= \frac{\partial}{\partial x}\bigg[\frac{\partial}{\partial y}(x^2y + \sin{x})\bigg] \\ &= 2x \end{aligned}

\displaystyle \begin{aligned} \frac{\partial ^2 f}{\partial y^2} &= 0 \end{aligned}

Similarly for $V = \pi r^2 h$ we have:

$\displaystyle \frac{\partial ^2 V}{\partial r^2} = V_{rr} = 2 \pi h$

$\displaystyle \frac{\partial ^2 V}{\partial r \partial h} = V_{rh} = 2 \pi r$

$\displaystyle \frac{\partial ^2 V}{\partial h \partial r} = V_{hr} = 2 \pi r$

$\displaystyle \frac{\partial ^2 V}{\partial h^2} = V_{hh} = 0$

For commonly encountered functions $f_{xy}$ we have that

$\displaystyle \frac{\partial ^2 f}{\partial x \partial y} = \frac{\partial ^2 f}{\partial y \partial x}$

From here on we may assume that all the mixed derivatives are equal.

Note, the normal rules (sum, product, quotient, function of a function) of differentiation apply to partial differentiation.