# How do I calculate the Jacobian matrix $Dh(x)$ of $h:V\rightarrow \mathbb{R}^m, x\mapsto f(x,g(x))$ with $V\subset \mathbb{R}^n$?

$$U\subset \mathbb{R}^n\times \mathbb{R}^m$$, $$V\subset \mathbb{R}^n$$ and $$W\subset \mathbb{R}^m$$ are open sets with $$V\times W \subset U$$.

Let the functions $$g:V\rightarrow W$$ and $$f:U\rightarrow \mathbb{R}^m,x\mapsto f(x,y)$$ be continuously differentiable.

Now I want to use the chain rule for multiple variables to calculate the Jacobian matrix $$Dh(x)$$ of $$h:V\rightarrow \mathbb{R}^m, x\mapsto f(x,g(x))$$, but I have problems with it.

Notation: $$\partial_{x_i}=\frac{\partial}{\partial x_i};\, f_i(x,g(x))=f_i(x_1,...,x_n,g_1(x),...,g_m(x))$$

$$Dh(x)=\begin{pmatrix} \partial_{x_1}(h_1(x))&... &\partial_{x_n}(h_1(x))\\ \vdots& &\vdots \\ \partial_ {x_1}(h_m(x))&... &\partial_{x_n}(h_m(x))\end{pmatrix}=\begin{pmatrix} \partial_{x_1}f_1(x,g(x)) &... &\partial_{x_n}f_1(x,g(x))\\ \vdots& &\vdots \\ \partial_{x_1}f_m(x,g(x))&... &\partial_{ x_n}f_m(x,g(x))\end{pmatrix}$$

How can I calculate(?): $$\frac{\partial }{\partial x_i}f_i(x,g(x))=\frac{\partial }{\partial x_i}f_i(x_1,...,x_n,g_1(x),. ..,g_m(x))=?$$

## 2 Answers

General rule for finding partial derivative of composition. Let $$z=g(y^1,\dots,y^n)$$ be a real-valued function of the real variables $$y^1,\dots,y^n$$, each of which in turn is a function $$y^j=f^j(x^1,\dots,x^m)\ (j=1,\dots,n)$$ of the variables $$x^1,\dots,x^m$$. Assuming that the functions $$g$$ and $$f^j$$ are differentiable $$(j=1,\dots,n)$$, we can find the partial derivative $$\dfrac{\partial (g\circ f)}{\partial x^i}(x)$$ of the composition of the mapping $$f:X\to Y$$ and $$g:Y\to \mathbb{R}$$.

$$\partial _i(g\circ f)(x)=\partial_jg(f(x))\cdot \partial _if^{j}(x),$$ or in notation that shows more detail $$\frac{\partial z}{\partial x^i}(x)=\frac{\partial(g\circ f)}{\partial x^i}(x^1,\dots,x^m)=\frac{\partial g}{\partial y^1}\cdot \frac{\partial y^1}{\partial x^i}+\dots+\frac{\partial g}{\partial y^n}\cdot \frac{\partial y^n}{\partial x^i}=$$ $$=\partial_1g(f(x))\cdot \partial_i f^1(x)+\dots+\partial_ng(f(x))\cdot \partial_i f^n(x).$$

Our problem. For concreteness let's compute the following partial derivative (here I am using a bit different notation): $$\frac{\partial}{\partial x^1}f^1(x^1,\dots,x^n,g^1(x),\dots, g^m(x))=$$ $$=\partial_1 f^1\cdot (x^1)'_1+\dots+\partial_n f^1\cdot (x^n)'_1+\partial_{n+1}f^1 \cdot \partial_1g^1+\dots+\partial_{n+m}f^1 \cdot \partial_1g^m=$$ $$=\partial_1 f^1+\partial_{n+1}f^1 \cdot \partial_1g^1+\dots+\partial_{n+m}f^1 \cdot \partial_1g^m.$$

Writing $$f:U\rightarrow \mathbb{R}^m,x\mapsto f(x,y)$$ is not correct. The function $$f$$ is defined on $$U$$, thus it is a function $$z \mapsto f(z)$$ where $$z = (x,y) \in U$$ with $$x \in \mathbb R^n, y \in \mathbb R^m$$.

Define $$\phi : V \to U, \phi(x) = (x,g(x)).$$ This function is continuously differentiable because its coordinate functions $$\phi_i(x) = \begin{cases} x_i & i = 1,\ldots,n \\ g_{n-i}(x) & i = n+1,\ldots, n+m \end{cases}$$ are continuously differentiable. Its Jacobian is $$D\phi(x) = \begin{pmatrix} 1 & 0 & \ldots & 0 \\ \vdots& & & \vdots \\ 0 & \ldots & 0 & 1 \\ \partial_{x_1}g_1(x)&... & & \partial_{x_n}g_1(x) \\ \vdots& & & \vdots \\ \partial_{x_1}g_m(x)&... & & \partial_{x_n}g_m(x) \end{pmatrix}$$

We have $$h = f \circ \phi$$, thus $$Dh(x) = Df(\phi(x))D\phi(x)$$. Since $$Df(z) = \begin{pmatrix} \partial_{x_1}f_1(z)&... & \partial_{x_n}f_1(z) & \partial_{y_1}f_1(z) & \ldots \partial_{y_m}f_1(z)\\ \vdots& & & \vdots \\ \partial_{x_1}f_m(z)&... & \partial_{x_n}f_m(z) & \partial_{y_1}f_m(z) & \ldots \partial_{y_m}f_m(z) \end{pmatrix}$$ we get $$Dh(x) = (a_{ij})$$ which is an $$(m \times n)$$-matrix with $$a_{ij} = \partial_{x_j}f_i(x,g(x))+ \sum_{k=1}^m\partial_{y_k}f_i(x,g(x))\partial_{x_j}g_k(x) .$$