Calculating derivative $D(g \circ f)$ for $f(x,y) := (x^2 + y^2, \sin(xy))$ using chain rule in two ways

99 Views Asked by At

Define $f, g: \mathbb{R}^2 \rightarrow \mathbb{R}^2$ as \begin{align*} f(x,y) := (x^2 + y^2, \sin(xy)) \\ g(x,y) := (xy, e^{y}) \end{align*} Compute the derivative $D(g \circ f)$ in two ways: using the chain rule and by first writing out the map $g \circ f: \mathbb{R}^2 \rightarrow \mathbb{R}^2$ explicitly.

I need help for this question..

My idea:

First we will calculate the derivative $D(g \circ f)$ using the chain rule. We have \begin{align*} Df(x,y) &= \begin{pmatrix} \frac{\partial f_1}{\partial x}(x^2 + y^2) & \frac{\partial f_1}{\partial y}(x^2 + y^2) \\ \frac{\partial f_2}{\partial x}(\sin(xy)) & \frac{\partial f_2}{\partial y}(\sin(xy)) \end{pmatrix} = \begin{pmatrix} 2x & 2y \\ y\cos(xy) & x\cos(xy) \end{pmatrix} \\ \end{align*} and \begin{align*} Dg(x,y) &= \begin{pmatrix} \frac{\partial g_1}{\partial x}(xy) & \frac{\partial g_1}{\partial y}(xy) \\ \frac{\partial g_2}{\partial x}(e^y) & \frac{\partial g_2}{\partial y}(e^y) \end{pmatrix} = \begin{pmatrix} y & x \\ 0 & e^y \end{pmatrix} \end{align*} Now we can calculate $D(g \circ f)(x,y)$: \begin{align*} D(g \circ f)(x,y) &= Dg(f(x,y)) \circ Df(x,y) \\ & = Dg(x^2 + y^2, \sin(xy)) \circ Df(x,y) \\ &= \begin{pmatrix} \sin(xy) & x^2 + y^2 \\ 0 & e^{\sin(xy)} \end{pmatrix} \circ \begin{pmatrix} 2x & 2y \\ y\cos(xy) & x\cos(xy) \end{pmatrix} \\ &= \begin{pmatrix} 2x\sin(xy) + x^2y\cos(xy) + y^3 \cos(xy) & 2y\sin(xy) + x^3\cos(xy) + xy^2\cos(xy) \\ e^{\sin(xy)}y\cos(xy) & e^{\sin(xy)}x\cos(xy) \end{pmatrix}. \end{align*} Now we will calculate the derivative $D(g \circ f)(x,y)$ by writing out the map $g \circ f: \mathbb{R}^2 \rightarrow \mathbb{R}^2$: \begin{align*} (g \circ f)(x,y) &= g(f(x,y)) \\ &= g(x^2 + y^2, \sin(xy)) \\ &= (x^2\sin(xy) + y^2\sin(xy), e^{\sin(xy)}) \end{align*} We can find the derivative again: \begin{align*} D(g \circ f)(x,y) &= \begin{pmatrix} \frac{\partial}{\partial x} (x^2\sin(xy) + y^2\sin(xy)) & \frac{\partial}{\partial y} (x^2\sin(xy) + y^2\sin(xy)) \\ \frac{\partial}{\partial x} (e^{\sin(xy)}) & \frac{\partial}{\partial y} (e^{\sin(xy)})\end{pmatrix} \\ &= \begin{pmatrix} 2x\sin(xy) + x^2y\cos(xy) + y^3\cos(xy) & x^3\cos(xy) + 2y\sin(xy) + xy^2\cos(xy) \\ e^{\sin(xy)}y\cos(xy) & e^{\sin(xy)} x\cos(xy) \end{pmatrix} \end{align*} Both methods give the same derivative.

2

There are 2 best solutions below

0
On BEST ANSWER

$\def\<{\langle}\def\>{\rangle}$We have the functions in $\Bbb R^2\mapsto\Bbb R^2$.

$$\begin{align}f:\<x,y\>&\mapsto \<x^2+y^2, \sin xy \>\\ g:\<x,y\>&\mapsto\<xy,\mathrm e^y\>\end{align}$$

The chain rule is $\def\D{\mathcal D}\D(g\circ f)=(\D g\circ f)\D f $

Let's examine the latter. Remember to compose $\D g$ with $f$.

$$\begin{align} \D g:\<x,y\>&\mapsto\begin{bmatrix}y&x\\0&\mathrm e^y\end{bmatrix}\\\D g\circ f:\<x,y\> &\mapsto\begin{bmatrix}\sin xy&x^2+y^2\\0&\mathrm e^{\sin xy}\end{bmatrix}\\\D f:\<x,y\>&\mapsto\begin{bmatrix}2x&2y\\y\cos xy&x\cos xy\end{bmatrix}\\(\D g\circ f)\D f:\<x,y\>&\mapsto\begin{bmatrix}2x\sin xy+(x^2+y^2)y\cos xy&2y\sin xy+(x^2+y^2)x\cos xy\\y\mathrm e^{\sin xy}\cos xy&x\mathrm e^{\sin xy}\cos xy\end{bmatrix}\tag 1\end{align}$$

Now the former.

$$\begin{align}g\circ f:\<x,y\>&\mapsto((x^2+y^2)\sin xy, \mathrm e^{\sin xy}\>\\\D(g\circ f):\<x,y\>&\mapsto\begin{bmatrix}2x\sin xy+(x^2+y^2)y\cos xy&2y\sin xy+(x^2+y^2)x\cos xy\\y\mathrm e^{\sin xy}\cos xy&x\mathrm e^{\sin xy}\cos xy\end{bmatrix}\tag 2\end{align}$$

3
On

The mistake is when you construct the matrix $Dg(f(x,y))$, before multiplying it with $Df(x,y)$. You calculated the derivative $Dg$ correctly, but to use it in the chain rule correctly you have to evaluate it at $f(x,y)$, not at $(x,y)$.

Remember what a derivative is: it lets you estimate what small change in the output should result from a small change in the input. The input to the function $g$ is only a small change away $f(x,y)$ so to estimate the change in the output we need to use the derivative at $f(x,y)$. So you need to substitute $x^2 + y^2$ and $sin(xy)$ at the appropriate points.

One way to prevent this sort of error is to do what your original version of the question did that this version doesn't: use variables $u$ and $v$ so that $g(u,v) = (uv, e^v)$. This should help you avoid conflating the variables in the input to $f$ with the variables that are the input to $g$.