Skip to main content

Vector-valued functions, product rule and chain rule with matrices

Author
Affiliation

Department of Economics, University of Houston

Published

November 30, 2026

Part of Math Camp: An Introduction to Mathematics and Statistics with Applications in Economics.
Main Stam4Econ site | View this section in the book | Author: Fan Wang | DOI: 10.5281/zenodo.24696926
Date: 2026-11-30 | HTML | PDF | QMD

1 Vector-valued functions, product rule and chain rule with matrices

1.1 Jacobian

Let \(f(\mathbf{x})\) be a vector-valued function that maps an n by 1 vector \(\mathbf{x}\) to an m by 1 vector \(\mathbf{y}\), i.e., \(f: \mathbb{R}^n \rightarrow \mathbb{R}^m\).

\[ df = J_f(\mathbf{x}) d\mathbf{x} = f'(\mathbf{x}) d\mathbf{x} \]

where \(J_f(\mathbf{x})\) is the Jacobian matrix of \(f\) at \(\mathbf{x}\), which is an m by n matrix where the element in the i-th row and j-th column is the partial derivative of the i-th component of \(f\) with respect to the j-th component of \(\mathbf{x}\).

In the case when \(n=2\) and \(m=2\), we have:

\[ \begin{bmatrix} df_1 \\ df_2 \end{bmatrix} = \begin{bmatrix} \frac{\partial f_1}{\partial x_1} & \frac{\partial f_1}{\partial x_2} \\ \frac{\partial f_2}{\partial x_1} & \frac{\partial f_2}{\partial x_2} \end{bmatrix} \begin{bmatrix} dx_1 \\ dx_2 \end{bmatrix} \]

In scalar calculus, we wrote \(\frac{df}{dx} = f'(x)\). In matrix calculus, we can no longer write \(\frac{df}{dx}\) because \(f\) and \(x\) are vectors. Instead, we write \(df = J_f(x) dx\) or \(df = f'(x) dx\), understanding their respective dimensions. But just like in scalar calculus, the \(df\) represents a small change in \(f\) when \(x\) changes by a small amount \(dx\).

1.2 The product rule

Suppose we have \(H(X) = U(X) V(X)\), where \(U(X)\) and \(V(X)\) are “product-conforming”. What does it mean for them to be “product-conforming”? It means that the number of columns in \(U(X)\) must equal the number of rows in \(V(X)\), so that the matrix product \(U(X)V(X)\) is defined. If \(U(X)\) is a row vector and \(V(X)\) is a column vector, then their product is a scalar.\(U(X)\) or \(V(X)\) might be constant matrixes that do not include \(X\). The product rule extends to matrix calculus:

\[ dH = U dV + dU V \]

where \(dH\), \(dU\), and \(dV\) are the differentials of \(H(X)\), \(U(X)\), and \(V(X)\), respectively.

Proposition: if \(H(X) = U(X) V(X)\), then \(dH = U dV + dU V\), where \(dH\), \(dU\), and \(dV\) are the differentials of \(H(X)\), \(U(X)\), and \(V(X)\), respectively, and \(U(X)\) and \(V(X)\) are “product-conforming” matrices.

Proof: First we begin with expressing the definition of the differential and plugging in the definition of \(H(X)\):

\[\begin{align} dH(X) &= H(X + dX) - H(X)\\ &= U(X + dX)V(X + dX) - U(X)V(X)\\ \end{align}\]

Second, we use the definition of differential again to replace \(U(X + dX)\) and \(V(X + dX)\) with \(U(X) + dU\) and \(V(X) + dV\), respectively:

\[\begin{align} &U(X + dX)V(X + dX) - U(X)V(X)\\ =& (U(X) + dU)(V(X) + dV) - U(X)V(X)\\ \end{align}\]

Third, we use the distributive property of matrix multiplication to expand the product \((U(X) + dU)(V(X) + dV)\), and have two terms cancel out.

\[\begin{align} & (U(X) + dU)(V(X) + dV) - U(X)V(X)\\ =& U(X)V(X) + U(X)dV + dU V(X) + dU dV - U(X)V(X)\\ =& U(X)dV + dU V(X) + dU dV\\ =& U(X)dV + dU V(X) \end{align}\]

We ignore the last term \(dU dV\) because it is the square of two infinitesimals, and we are left with the first two terms. This is the product rule.

1.3 The chain rule

Similar to the product rule, we can extend the chain rule to matrix calculus. Suppose we have \(H(X) = U(V(X))\), where \(U\) is a function that takes a matrix as input and outputs another matrix, and \(V(X)\) is a function that takes a matrix as input and outputs another matrix. The chain rule states that:

\[ dH(X) = U'(V(X)) V'(X) dX = H'(X) dX \]

In this case, \(U'(V(X))\) is jacobian of \(U\) with respect to its input V, and V’(X) is the jacobian of V with respect to X. If \(H(X) \in R^{m}\), \(V(X) \in R^{n}\), and \(X \in R^{p}\), then \(U'(V(X))\) is an m by n matrix, and \(V'(X)\) is an n by p matrix. Thus, \(H'(X) = U'(V(X)) V'(X)\) is an m by p matrix.

Similar to the product rule, the chain rule can be proved using the definition of differential and ignoring the square of infinitesimals.

1.4 Matrix differential example, scalar matrix

Now we have an example, where we need to use the chain rule and the product rule together. The example is, let \(A\) be a \(n\) by \(k\) matrix, and \(X \in R^{k}\), and \(g: R^{k} \rightarrow R^{m}\). We define \(f\) as:

\[ f(X) = g(A^{T}AX) \]

We apply the chain rule and the product rule to find the differential of \(f(X)\) with respect to \(X\).

\[\begin{align} df(X) &= g'(A^{T}AX) d(A^{T}AX)\\ &= g'(A^{T}AX) ((A^{T}A) (dX) + (d(A^{T}A)) X)\\ &= g'(A^{T}AX) (A^{T}A dX + 0)\\ &= g'(A^{T}AX) A^{T}A dX\\ \end{align}\]

Thus, the jacobian of \(f(X)\) with respect to \(X\) is:

\[ f'(X) = g'(A^{T}AX) (A^{T}A) \]

1.5 Matrix differential example, “cubic” triple product

We have another example, where we need to use the chain rule and the product rule together again. The example is, let \(A\) be a \(n\) by \(k\) matrix, and \(X \in R^{k}\), and \(g: R^{k} \rightarrow R^{m}\). We define \(f\) as:

As an example, we have a “triple product”:

\[ f(X) = g(XX^{T}X) \]

We apply the chain rule and the product rule to find the differential of \(f(X)\) with respect to \(X\).

\[\begin{align} df(X) &= g'(XX^{T}X) d(XX^{T}X)\\ &= g'(XX^{T}X) (X X^{T} dX + d(XX^T) X)\\ &= g'(XX^{T}X) (X X^{T} dX + (Xd(X^T) + dX X^T) X)\\ &= g'(XX^{T}X) (X X^{T} dX + Xd(X)^TX + dX X^T X)\\ \end{align}\]

In the last line we distribute, and also use the fact that \(d(X^T) = d(X)^T\) (the differential of a transpose is the transpose of the differential). Now note that \(X^T X\) is a scalar, and also \(d(X)^T X\) is a scalar. Hence, they are equal to their own transposes, and we can move scalar. Thus, we have:

\[\begin{align} df(X) &= g'(XX^{T}X) (X X^{T} dX + Xd(X)^TX + dX X^T X)\\ &= g'(XX^{T}X) (X X^{T} dX + XX^TdX + X^T X dX)\\ &= g'(XX^{T}X) (2 X X^{T} + X^TX I) dX\\ \end{align}\]

where \(I\) is the identity matrix. Thus, the jacobian of \(f(X)\) with respect to \(X\) is:

\[ f'(X) = g'(XX^{T}X) (2 X X^{T} + X^TX I) \]

What if we were in the scalar algebra world, and had:\(f(x) = g(x^3)\), where \(x\) is a scalar. Then we would have:

\[\begin{align} df(x) &= g'(x^3) d(x^3)\\ &= g'(x^3) 3x^2 dx\\ \end{align}\]

Suppose \(k=1\), then \(X\) is a scalar, is the matrix-calculus derived result consistent with the scalar-calculus derived result? Yes:

\[\begin{align} df(X) &= g'(XX^TX) (2 X X^{T} + X^TX I) dX\\ &= g'(X^3) (2 X^2 + X^2) dX\\ &= g'(X^3) 3X^2 dX\\ \end{align}\]