# Using chain rule for derivative of multivariable function

I've been trying to learn more about the chain rule of a multivariable function, but I'm a bit confused on a special case I've encountered. I'm given a single valued function

$$\displaystyle f(x_1,x_2,x_3)$$

evaluated at $$x_3 = g(x_1,x_2)$$, which is also a single valved function. Note that $$x_n$$ are all scalars. I think I would summarize the functions as $$f:\mathbb{R}^3\rightarrow \mathbb{R}$$ and $$g:\mathbb{R}^2\rightarrow \mathbb{R}$$. I'm going to represent the function composition as

$$\displaystyle h(x_1,x_2) = f(x_1,x_2,g(x_1,x_2)) \equiv (f \circ g)(x_1,x_2)$$

in which $$h:\mathbb{R}^2\rightarrow \mathbb{R}$$. I'm told to find the derivative of $$h$$ with respect to $$x_2$$. However, I want to write down the general expression for the derivative. Following the link above (and material within), I can use the so called derivative operator $$\textbf{D}$$ and write

$$\displaystyle \textbf{D}h = \textbf{D}f|_{x_3=g}\textbf{D}g$$

where I've introduced the notation $$|_{x_3=g}$$ to denote "is evaluated at $$x_3 = g(x_1,x_2)$$" and dropped the other function variables for clarity. What I don't follow is how to write this in terms of vector/matrix products. In some of the linked material, it says the derivative of a scalar valued function is expressed as a $$1 \times n$$ row vector. Therefore,

$$\displaystyle \textbf{D}h = \left[ \frac{\partial h}{\partial x_1} \quad \frac{\partial h}{\partial x_2}\right]$$

$$\displaystyle \textbf{D}f|_{x_3=g} = \left[ \frac{\partial f}{\partial x_1}|_{x_3=g} \quad \frac{\partial f}{\partial x_2}|_{x_3=g} \quad \frac{\partial f}{\partial x_3}|_{x_3=g} \right]$$

$$\displaystyle \textbf{D}g = \left[ \frac{\partial g}{\partial x_1} \quad \frac{\partial g}{\partial x_2}\right]$$

I know the answer, specific to the question: "find the derivative of $$h$$ with respect to $$x_2$$" is

$$\displaystyle \frac{\partial h}{\partial x_2} = \frac{\partial f}{\partial x_2}|_{x_3=g} + \frac{\partial f}{\partial x_3}|_{x_3=g} \frac{\partial g}{\partial x_2}$$

so, my question is not about the answer. I'm trying to see how I would arrive at that using vector/matrix products? Specifically, the form "$$\displaystyle \textbf{D}h = \textbf{D}f|_{x_3=g}\textbf{D}g$$" is easy to remember (from single variable days), and if I can understand how to use it for all special cases, that would be helpful (using the case presented here to showcase).

• Your equation $h = f\circ g$ is just wrong. However, Literally showed you the correct composition. Mar 26, 2021 at 4:36
• Yes, you're right...instead of correcting the question, I just pointed to the answer/comments. Mar 26, 2021 at 4:50

Define $$G(x,y)=(x,y,g(x,y))$$ and consider $$f \circ G=f(x,y,g(x,y))$$. Now we have
$$DG= \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ g_x & g_y \end{bmatrix}$$ and $$Df=[f_x, f_y, f_z]$$. Now $$Df \circ DG = [f_x + f_z g_x , f_y+f_z g_y]$$ and we get what you have, $$h_y=f_y+f_z g_y$$
The problem was that you didn't set up the $$G$$ correctly.
• Just to clarify..."G" here is a vector-valued multivariable function? So the composition can also be expressed as "f(G)" (i.e. f(G) = f(x,y,g(x,y)) )? Lastly, what you've shown here for $\textbf{D}f \circ \textbf{D}G$ is 3 components in brackets, with the last being zero. Therefore, is it OK that I have defined "h" as "$h(x_1,x_2)$" (i.e. 2d vs 3d domain)? Even though you've shown the terms in brackets, is it understood that those terms are summed to produce a scalar value ("h" is scalar valued function) or do I have to emphasize that in some way? Mar 26, 2021 at 3:14
• The terms in the brackets are the partials oh h as per the chain rule, i.e. we have $[h_x, h_y, h_z]$. The problem is that f takes values in $R^3$ so you need G to also take values in $R^3$ Mar 26, 2021 at 3:27
• Basically, this $h(x_1,x_2) = f(x_1,x_2,g(x_1,x_2)) \equiv (f \circ g)(x_1,x_2)$ should be replaced with $h(x_1,x_2,x_3) = f(G(x_1,x_2,x_3)) \equiv (f \circ G)(x_1,x_2,x_3)$, where $G(x_1,x_2,x_3) = <x_1,x_2,g(x_1,x_2)>$ (where < > denotes a vector)? Mar 26, 2021 at 3:58
• $f \circ g$ doesn't make sense because g is a real number, not a vector. i.e. $g: R^2 \to R$. and $G : R^2 \to R^3$. Mar 26, 2021 at 4:02
• Ahh....I think I see now. This is wrong $f(x_1,x_2,g(x_1,x_2)) \equiv (f \circ g)(x_1,x_2)$. The composition, as I wrote, is $(f \circ g)(x_1,x_2) \equiv f(g(x_1,x_2))$, which is not how $f$ is defined (i.e. takes $\mathbb{R}^3$ as the domain). Mar 26, 2021 at 4:21