# June 14, 2006

## The Chain Rule… inside out!

Posted in Mathematics at 11:39 am by pmatos

The Chain Rule is definitely an extremely useful tool, whether you’re working in single-variable calculus or multi-variable calculus. Since I had some fun with it today I’ll give a brief explanation here today… hopefully I’ll help someone in the future!

Chain Rule for single-variable functions ($$f : \mathbb{R} \rightarrow \mathbb{R}$$)

This is the simplest case and in fact to understand the rule for the general case you should start here.

Basically consider $$g = f(r(t))$$, so we simply have $$g'(t) = f'(r(t)) \cdot r'(t)$$.
As an example, consider:
$$f(x) = 1/x$$ and,
$$r(t) = t^2, t \neq 0$$.
So if we wish to compute the derivative of $$g(t) = f(r(t))$$, we just need to apply the chain rule above:
$$g'(t) = f'(r(t)) \cdot r'(t) =$$
$$= f'(t^2) \cdot 2t =$$
$$= -1/(t^2) \cdot 2t = \frac{-2t}{t^2} = \frac{-2}{t}$$

I left the obvious part unmentioned (the why I had to restrict $$r$$). Since, $$D_f = ]-\infty, 0[ \cup ]0, +\infty[$$ and $$D^’_g = \mathbb{R}$$, this is only valid if we restrict $$r$$.

Now, onto a more general case.

Chain Rule for multi-variable functions ($$f : \mathbb{R}^n \rightarrow \mathbb{R}$$)

So, given a scalar field defined on an open set $$S$$ in $$\mathbb{R}^n$$, and let $$r$$ be a vector-valued function which maps an interval J from $$\mathbb{R}^1$$ into $$S$$. Define the composite function $$g = f \circ r$$ on $$J$$ by the equation:
$$g(t) = f[r(t)]$$ if $$t \in J$$

Let $$t$$ be a point in $$J$$ at which $$r'(t)$$ exists and assume that $$f$$ is differenciable at $$r(t)$$. Then $$g'(t)$$ exists and is equal to the dot product:
$$g'(t) = \nabla f(a) \cdot r'(t)$$, where $$a = r(t)$$

Note that $$\nabla f(a)$$ known as the gradient of $$f$$ at $$a$$ is the vector whose components are the partial derivatives of $$f$$ at $$a$$:
$$\nabla f(a) = (D_1 f(a), \ldots, D_n f(a))$$

So, $$\nabla f(a)$$ is a vector field defined at each point $$a$$ where the partial derivatives $$D_1 f(a), \ldots, D_n f(a)$$ exist.

Consider that $$F = f \circ r$$ and as we have been considering in this section $$f : \mathbb{R}^2 \rightarrow \mathbb{R}$$ and $$r : \mathbb{R} \rightarrow \mathbb{R}^2$$, so we have that $$F : \mathbb{R} \rightarrow \mathbb{R}$$. They are given by $$f(x, y) = x^2 + y^2, r(t) = (t, t^2)$$ and let’s compute $$F'(t), F”(t)$$.

By using the chain rule we have: $$F'(t) = \nabla f(r(t)) \cdot r'(t)$$. So,
$$\nabla f = \left(\frac{\partial f}{\partial x}, \frac{\partial f}{\partial y}\right) = (2x, 2y)$$ and
$$r'(t) = (1, t^2)$$

Substituting in the chain rule:
$$F'(t) = \nabla f(r(t)) \cdot r'(t) =$$
$$= (2t, 2t^2) \cdot (1, 2t) =$$
$$= 2t + 4t^3$$

And trivially, we need no chain rule for the second derivative: $$F”(t) = [F'(t)]’ = 12t^2+2$$.

In general, the chain rule for multi-variable vector fields ($$f : \mathbb{R}^n \rightarrow \mathbb{R}^m$$)

Now, let’s look at the general case when we have vector fields.
Chain Rule: Let $$f$$, and $$g$$ be vector fields such that the composition $$h = f \circ g$$ is defined in a neighborhood of a point $$a$$. Assume that $$g$$ is differentiable at $$a$$, with total derivative $$g'(a)$$. Let $$b = g(a)$$ and assume that $$f$$ is differentiable at $$b$$, with total derivative $$f'(b)$$. Then $$h$$ is differentiable at $$a$$, and the total derivative $$h'(a)$$ is given by:
$$h'(a) = f'(b) \circ g'(a)$$,
the composition of the linear transformations $$f'(b)$$ and $$g'(a)$$.

Note that the derivatives of vector fields are given by their respective jacobian matrices and that the composition of the linear transformation is obtained by the multiplication of the jacobian matrices (which represent the linear transformations).

Ok, so let’s try to do a complete exercise (since officially, or from a theoretical point-of-view, we already know how to do it).
Given:
$$f: \mathbb{R}^2 \rightarrow \mathbb{R}^2$$
$$f(x, y) = (e^{x+2y}, \sin(y+2x))$$
$$g: \mathbb{R}^3 \rightarrow \mathbb{R}^2$$
$$g(u,v,w) = (u + 2v^2 + 3w^3, 2v-u^2)$$

Let’s compute the jacobian matrices of $$f$$ and $$g$$:
$$D_f = \begin{pmatrix} \frac{\partial f_1}{\partial x} & \frac{\partial f_1}{\partial y} \\ \frac{\partial f_2}{\partial x} & \frac{\partial f_2}{\partial y} \end{pmatrix} =$$
$$= \begin{pmatrix} e^{x+2y} & 2e^{x+2y} \\ 2\cos(y+2x) & \cos(y+2x) \end{pmatrix}$$

$$D_g = \begin{pmatrix}\frac{\partial g_1}{\partial u} & \frac{\partial g_1}{\partial v} & \frac{\partial g_1}{\partial w}\\ \frac{\partial g_2}{\partial u} & \frac{\partial g_2}{\partial v} & \frac{\partial g_2}{\partial w}\end{pmatrix} =$$
$$= \begin{pmatrix}1 & 4v & 9w^2 \\ -2u & 2 & 0 \end{pmatrix}$$

Now, define $$h(u,v,w) = f(g(u,v,w))$$ and compute $$D_h(1,-1,1)$$. Well, well… here’s the application of our chain rule. So, by the chain rule:
$$h(1,-1,1) = f'(g(1,-1,1)) \circ g'(1,-1,1)$$

By substitution in the expression:
$$g(1,-1,1) = (1+2+3, -2-1) = (6,-3)$$

By substituting in the jacobian matrix computed previously for $$f$$ the value of $$g(1,-1,1)$$:
$$f'(g(1,-1,1)) = f'(6,3) = \begin{pmatrix} 1 & 2 \\ 2\cos(9) & \cos(9) \end{pmatrix}$$

By substituting in the jacobian matrix computed previously for $$g$$:
$$g'(1,-1,1) = \begin{pmatrix} 1 & -4 & 9 \\ -2 & 2 & 0 \end{pmatrix}$$

Now that we have computed all the values needed for the chain rule application, applying it is just composing the linear transformations given by the derivatives of $$f$$ and $$g$$, which is another way of saying that we need to multiply their jacobian matrices:
$$h'(1,-1,1) = \begin{pmatrix} 1 & 2 \\ 2\cos(9) & \cos(9) \end{pmatrix} \cdot \begin{pmatrix} 1 & -4 & 9 \\ -2 & 2 & 0 \end{pmatrix} =$$
$$= \begin{pmatrix}-3 & 0 & 9 \\ 0 & -6\cos(9) & 18\cos(9) \end{pmatrix}$$

And we’re done… :-)
Computing Jacobian’s and working with these kinds of tools are extremelly helpful in Geometry, Differential Calculus and some branches of Physics.

References:

• Weisstein, Eric W. “Chain Rule.” From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/ChainRule.html
• Apostol, Tom “Calculus”, Volume II, Second Edition
• Anton, Bivens and Davis, Calculus, Seventh Edition