Product rule for matrix-valued and vector-valued functions Given $g: \mathbb{R}^n \to \mathbb{R}^{n \times m}$ and $f: \mathbb{R}^n \to \mathbb{R}^{m}$ how can we compute $\nabla (g(x)f(x))$?

The $(i,j)$-term of $\nabla(fg)$ is given by
\begin{align}
\partial_i((g(x)f(x))_j) &= \partial_i\left(\sum_{k=1}^n g_{kj}(x)f_k(x)\right)\\
&= \sum_{k=1}^n (\partial_ig_{kj})(x)f_k(x) + \sum_{k=1}^n g_{kj}(x)(\partial_i f_k)(x)\\
&= ((\partial_ig)(x)f(x))_j + (g(x)(\partial_i f)(x))_j
\end{align}
so
\begin{align*}
\nabla(g(x)f(x)) &= \begin{bmatrix} \partial_i((g(x)f(x))_j)\end{bmatrix}_{i,j=1}^n \\
&= \begin{bmatrix} (\partial_1 g)(x)f(x)\\ \vdots \\ (\partial_n g)(x)f(x)\end{bmatrix} + \begin{bmatrix} g(x)(\partial_1f)(x)\\ \vdots \\ g(x)(\partial_nf)(x)\end{bmatrix}\\
&= \begin{bmatrix} (\partial_1 g)(x)f(x)\\ \vdots \\ (\partial_n g)(x)f(x)\end{bmatrix} + g(x)(\nabla f(x))^T
\end{align*}
where $(\partial_i g)(x)$ is $\partial_i$ applied to the matrix $g$ elementwise. 
