Chain rule examples

Example 1

Let g : R R2 and f : R2 R be defined by

g(t) = (t3,t4) f(x,y) = x2y.

(You can think of this as the mountain climbing example where f(x,y) is height of mountain at point (x,y) and the path g(t) gives your position at time t.) Let h(t) be the composition of f with g (which would give your height at time t):

h(t) = (f g)(t) = f(g(t))

Calculate the derivative h'(t) = dh dt (t) (i.e., the change in height) via the chain rule.

Solution A: We’ll use the formula using matrices of partial derivatives:

Dh(t) = Df(g(t))Dg(t).

We calculate the matrices of partial derivatives of f and g.

Df(x,y) = f x(x,y)f y(x,y) = 2xyx2 Dg(t) = g1'(t) g2'(t) = 3t2 4t3

We need to evaluate Df at the point g(t):

Df(g(t)) = Df(t3,t4) = 2(t3)(t4)(t3)2 = 2t7t6

The derivative of h is

h'(t) = dh dt (t) = Dh(t) = Df(g(t))Dg(t) = 2t7t6 3t2 4t3 = (2t7)(3t2) + (t6)(4t3) = 6t9 + 4t9 = 10t9

Solution B: We’ll start immediately with the formula in component form:

dh dt (t) = f x(g(t))dg1 dt (t) + f y(g(t))dg2 dt (t).

We calculate

f x(x,y) = 2xy f y(x,y) = x2 f x(g(t)) = f x(t3,t4) = 2(t3)(t4) = 2t7 f y(g(t)) = f y(t3,t4) = (t3)2 = t6 dg1 dt (t) = 3t2 dg2 dt (t) = 4t3.

Therefore,

dh dt (t) = (2t7)(3t2) + (t6)(4t3) = 6t9 + 4t9 = 10t9.

Example 1’

Verify the chain rule for example 1 by calculating an expression for h(t) and then differentiating it to obtain dh dt (t).

Solution: h(t) = f(g(t)) = f(t3,t4) = (t3)2(t4) = t10.

h'(t) = dh dt (t) = 10t9,

which matches the solution to Example 1, verifying that the chain rule got the correct answer.

For this simple example, doing it without the chain rule was a lot easier. However, that is not always the case. And, in the next example, the only way to obtain the answer is to use the chain rule.

Example 2

We continue the mountain climbing example of Example 1. But now, let’s say we don’t know the terrain ahead of time. This means we do not yet know the height f(x,y) at the position (x,y). We do, however, know our path through mountain; as before, it is given by g(t) = (t3,t4).

Calculate the chain in height that you’ll experience along the path, i.e., calculate the derivative of h(t) = f(g(t)). In this case, since we don’t know f, the answer will be given in terms of the function f(x,y).

Solution: We’ll just copy solution A, above. This time, though, we must leave the matrix of partial derivatives of f as

Df(x,y) = f x(x,y)f y(x,y)

since we don’t know what f(x,y) is. We can substitute in the values along the path g(t):

Df(g(t)) = Df(t3,t4) = f x(t3,t4)f y(t3,t4) .

Since Dg(t) is the same as in solution A, above, we calculate the derivative of h as

h'(t) = Dh(t) = Df(g(t))Dg(t) = f x(t3,t4)f y(t3,t4) 3t2 4t3 = 3t2f x(t3,t4) + 4t3f y(t3,t4).

We leave the answer in this form. Of course, as soon as we know what f(x,y) is, we can simply compute its partial derivatives and plug the result into this formula.

Example 3

We continue using the same function f(x,y) = x2y to describe the height of the mountain at position (x,y). We embellish the above examples by letting g : R2 R2 be defined by g(s,t) = (t s2,ts2). (We could think of having many paths through the mountain that depend on a skill level s. Then, (x,y) = g(s,t) could be the position of a person at time t with skill level s.)

Compute s(f g)(s,t) and t(f g)(s,t), i.e., the partial derivatives with respect to s and t of the height of a person in the mountains whose position is given by g(s,t).

Solution: Let h(s,t) = (f g)(s,t) = f(g(s,t)). We need to calculate h s(s,t) and h t (s,t). The chain rule says that

Dh(s,t) = D(f g)(s,t) = Df(g(s,t))Dg(s,t).

Since

Dh(s,t) = h s(s,t)h t (s,t) ,

the answers we want are just the two components of Dh(s,t). We just need to calculate the matrices Df(g(s,t)) and Dg(s,t), then multiply them together.

To make it easier in case you have to do such a problem again, we’ll perform the matrix multiplication before writing in the specific values for f(x,y) and g(s,t). Then, we’ll end up with the chain rule written in component form, which may be easier to use.

The function f(x,y) hasn’t changed, so its matrix of partial derivatives is

Df(x,y) = f x(x,y)f y(x,y) .

For the chain rule, we need this evaluated at (x,y) = g(s,t)

Df(g(s,t)) = f x(g(s,t))f y(g(s,t)) .

Since g : R2 R2, its matrix of partial derivatives is a 2 × 2 matrix. If we denote its components as g(s,t) = (g1(s,t),g2(s,t)), its matrix of partial derivatives is

Dg(s,t) = g1 s (s,t)g1 t (s,t) g2 s (s,t) g2 t (s,t) .

The chain rule Dh(s,t) = Df(g(s,t))Dg(s,t) becomes

h s(s,t)h t (s,t) = f x(g(s,t))f y(g(s,t)) g1 s (s,t)g1 t (s,t) g2 s (s,t) g2 t (s,t)

We can compute the matrix product on the right-hand side; the result is a 1 × 2 matrix (i.e., the same size of Dh(s,t)). We obtain one equation by matching the first component of Dh(s,t) with the first component of this multiplied-out matrix. We obtain a second equation by matching the second component of Dh(s,t) with the second component of this multiplied-out matrix. The resulting two equations are

h s(s,t) = f x(g(s,t))g1 s (s,t) + f y(g(s,t))g2 s (s,t) h t (s,t) = f x(g(s,t))g1 t (s,t) + f y(g(s,t))g2 t (s,t).

This is the chain rule written out in component form for h : R2 R, f : R2 R, and g : R2 R2.

Now, we compute the answer to our specific problem by substituting in for f(x,y) = x2y and g(s,t) = (t s2,ts2).

f x(x,y) = 2xy f x(g(s,t)) = 2ts2(t s2) f y(x,y) = x2 f y(g(s,t)) = (t s2)2 g1 s (s,t) = 2s g2 s (s,t) = 2st g1 t (s,t) = 1 g2 t (s,t) = s2

Finally, we get our answers.

s(f g)(s,t) = h s(s,t) = f x(g(s,t))g1 s (s,t) + f y(g(s,t))g2 s (s,t) = 2ts2(t s2)(2s) + (t s2)2(2st) = 4ts3(t s2) + 2st(t 2ts2 + s4) = 4s3t2 + 4s5t + 2st2 4s3t2 + 2s5t = 8s3t2 + 6s5t + 2st2 t(f g)(s,t) = h t (s,t) = f x(g(s,t))g1 t (s,t) + f y(g(s,t))g2 t (s,t) = 2ts2(t s2)(1) + (t s2)2(s2) = 2s2t2 2s4t + s2t2 2s4t + s6 = 3s2t2 4s4t + s6