# Matrix calculus

In mathematics, matrix calculus is a specialized notation for doing multivariable calculus, especially over spaces of matrices. It collects the various partial derivatives of a single function with respect to many variables, and/or of a multivariate function with respect to a single variable, into vectors and matrices that can be treated as single entities. This greatly simplifies operations such as finding the maximum or minimum of a multivariate function and solving systems of differential equations. The notation used here is commonly used in statistics and engineering, while the tensor index notation is preferred in physics.

Two competing notational conventions split the field of matrix calculus into two separate groups. The two groups can be distinguished by whether they write the derivative of a scalar with respect to a vector as a column vector or a row vector. Both of these conventions are possible even when the common assumption is made that vectors should be treated as column vectors when combined with matrices (rather than row vectors). A single convention can be somewhat standard throughout a single field that commonly use matrix calculus (e.g. econometrics, statistics, estimation theory and machine learning). However, even within a given field different authors can be found using competing conventions. Authors of both groups often write as though their specific convention is standard. Serious mistakes can result when combining results from different authors without carefully verifying that compatible notations are used. Therefore great care should be taken to ensure notational consistency. Definitions of these two conventions and comparisons between them are collected in the layout conventions section.

## Scope

Matrix calculus refers to a number of different notations that use matrices and vectors to collect the derivative of each component of the dependent variable with respect to each component of the independent variable. In general, the independent variable can be a scalar, a vector, or a matrix while the dependent variable can be any of these as well. Each different situation will lead to a different set of rules, or a separate calculus, using the broader sense of the term. Matrix notation serves as a convenient way to collect the many derivatives in an organized way.

As a first example, consider the gradient from vector calculus. For a scalar function of three independent variables, $f(x_1, x_2, x_3)$, the gradient is given by the vector equation

$\nabla f = \frac{\partial f}{\partial x_1} \hat{x_1} + \frac{\partial f}{\partial x_2} \hat{x_2} + \frac{\partial f}{\partial x_3} \hat{x_3}$,

where $\hat{x_i}$ represents a unit vector in the $x_i$ direction for $1\le i \le 3$. This type of generalized derivative can be seen as the derivative of a scalar, f, with respect to a vector, $\mathbf{x}$ and its result can be easily collected in vector form.

$\nabla f = \frac{\partial f}{\partial \mathbf{x}} = \begin{bmatrix} \frac{\partial f}{\partial x_1} & \frac{\partial f}{\partial x_2} & \frac{\partial f}{\partial x_3} \\ \end{bmatrix}.$[citation needed]

More complicated examples include the derivative of a scalar function with respect to a matrix, known as the gradient matrix, which collects the derivative with respect to each matrix element in the corresponding position in the resulting matrix. In that case the scalar must be a function of each of the independent variables in the matrix. As another example, if we have an n-vector of dependent variables, or functions, of m independent variables we might consider the derivative of the dependent vector with respect to the independent vector. The result could be collected in an m×n matrix consisting of all of the possible derivative combinations. There are, of course, a total of nine possibilities using scalars, vectors, and matrices. Notice that as we consider higher numbers of components in each of the independent and dependent variables we can be left with a very large number of possibilities.

The six kinds of derivatives that can be most neatly organized in matrix form are collected in the following table.[1]

Types of Matrix Derivatives
Types Scalar Vector Matrix
Scalar $\frac{\partial y}{\partial x}$ $\frac{\partial \mathbf{y}}{\partial x}$ $\frac{\partial \mathbf{Y}}{\partial x}$
Vector $\frac{\partial y}{\partial \mathbf{x}}$ $\frac{\partial \mathbf{y}}{\partial \mathbf{x}}$
Matrix $\frac{\partial y}{\partial \mathbf{X}}$

Here, we have used the term "matrix" in its most general sense, recognizing that vectors and scalars are simply matrices with one column and then one row respectively. Moreover, we have used bold letters to indicate vectors and bold capital letters for matrices. This notation is used throughout.

Notice that we could also talk about the derivative of a vector with respect to a matrix, or any of the other unfilled cells in our table. However, these derivatives are most naturally organized in a tensor of rank higher than 2, so that they do not fit neatly into a matrix. In the following three sections we will define each one of these derivatives and relate them to other branches of mathematics. See the layout conventions section for a more detailed table.

### Relation to other derivatives

The matrix derivative is a convenient notation for keeping track of partial derivatives for doing calculations. The Fréchet derivative is the standard way in the setting of functional analysis to take derivatives with respect to vectors. In the case that a matrix function of a matrix is Fréchet differentiable, the two derivatives will agree up to translation of notations. As is the case in general for partial derivatives, some formulae may extend under weaker analytic conditions than the existence of the derivative as approximating linear mapping.

### Usages

Matrix calculus is used for deriving optimal stochastic estimators, often involving the use of Lagrange multipliers. This includes the derivation of:

## Notation

The vector and matrix derivatives presented in the sections to follow take full advantage of matrix notation, using a single variable to represent a large number of variables. In what follows we will distinguish scalars, vectors and matrices by their typeface. We will let M(n,m) denote the space of real n×m matrices with n rows and m columns. Such matrices will be denoted using bold capital letters: A, X, Y, etc. An element of M(n,1), that is, a column vector, is denoted with a boldface lowercase letter: a, x, y, etc. An element of M(1,1) is a scalar, denoted with lowercase italic typeface: a, t, x, etc. XT denotes matrix transpose, tr(X) is the trace, and det(X) is the determinant. All functions are assumed to be of differentiability class C1 unless otherwise noted. Generally letters from first half of the alphabet (a, b, c, …) will be used to denote constants, and from the second half (t, x, y, …) to denote variables.

NOTE: As mentioned above, there are competing notations for laying out systems of partial derivatives in vectors and matrices, and no standard appears to be emerging yet. The next two introductory sections use the numerator layout convention simply for the purposes of convenience, to avoid overly complicating the discussion. The section after them discusses layout conventions in more detail. It is important to realize the following:

1. Despite the use of the terms "numerator layout" and "denominator layout", there are actually more than two possible notational choices involved. The reason is that the choice of numerator vs. denominator (or in some situations, numerator vs. mixed) can be made independently for scalar-by-vector, vector-by-scalar, vector-by-vector, and scalar-by-matrix derivatives, and a number of authors mix and match their layout choices in various ways.
2. The choice of numerator layout in the introductory sections below does not imply that this is the "correct" or "superior" choice. There are advantages and disadvantages to the various layout types. Serious mistakes can result from carelessly combining formulas written in different layouts, and converting from one layout to another requires care to avoid errors. As a result, when working with existing formulas the best policy is probably to identify whichever layout is used and maintain consistency with it, rather than attempting to use the same layout in all situations.

### Alternatives

The tensor index notation with its Einstein summation convention is very similar to the matrix calculus, except one writes only a single component at a time. It has the advantage that one can easily manipulate arbitrarily high rank tensors, whereas tensors of rank higher than two are quite unwieldy with matrix notation. All of the work here can be done in this notation without use of the single-variable matrix notation. However, many problems in estimation theory and other areas of applied mathematics would result in too many indices to properly keep track of, pointing in favor of matrix calculus in those areas. Also, Einstein notation can be very useful in proving the identities presented here, as an alternative to typical element notation, which can become cumbersome when the explicit sums are carried around. Note that a matrix can be considered a tensor of rank two.

## Derivatives with vectors

Main article: Vector calculus

Because vectors are matrices with only one column, the simplest matrix derivatives are vector derivatives.

The notations developed here can accommodate the usual operations of vector calculus by identifying the space M(n,1) of n-vectors with the Euclidean space Rn, and the scalar M(1,1) is identified with R. The corresponding concept from vector calculus is indicated at the end of each subsection.

NOTE: The discussion in this section assumes the numerator layout convention for pedagogical purposes. Some authors use different conventions. The section on layout conventions discusses this issue in greater detail. The identities given further down are presented in forms that can be used in conjunction with all common layout conventions.

### Vector-by-scalar

The derivative of a vector $\mathbf{y} = \begin{bmatrix} y_1 \\ y_2 \\ \vdots \\ y_m \\ \end{bmatrix}$, by a scalar x is written (in numerator layout notation) as

$\frac{\partial \mathbf{y}}{\partial x} = \begin{bmatrix} \frac{\partial y_1}{\partial x}\\ \frac{\partial y_2}{\partial x}\\ \vdots\\ \frac{\partial y_m}{\partial x}\\ \end{bmatrix}.$

In vector calculus the derivative of a vector y with respect to a scalar x is known as the tangent vector of the vector y, $\frac{\partial \mathbf{y}}{\partial x}$. Notice here that y:R $\rightarrow$ Rm.

Example Simple examples of this include the velocity vector in Euclidean space, which is the tangent vector of the position vector (considered as a function of time). Also, the acceleration is the tangent vector of the velocity.

### Scalar-by-vector

The derivative of a scalar y by a vector $\mathbf{x} = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \\ \end{bmatrix}$, is written (in numerator layout notation) as

$\frac{\partial y}{\partial \mathbf{x}} = \left[ \frac{\partial y}{\partial x_1} \ \ \frac{\partial y}{\partial x_2} \ \ \cdots \ \ \frac{\partial y}{\partial x_n} \right].$

In vector calculus the gradient of a scalar field y, in the space Rn whose independent coordinates are the components of x is the derivative of a scalar by a vector. In physics, the electric field is the vector gradient of the electric potential.

The directional derivative of a scalar function f(x) of the space vector x in the direction of the unit vector u is defined using the gradient as follows.

$\nabla_{\bold{u}}{f}(\bold{x}) = \nabla f(\bold{x}) \cdot \bold{u}$

Using the notation just defined for the derivative of a scalar with respect to a vector we can re-write the directional derivative as $\nabla_\mathbf{u} f = \frac{\partial f}{\partial \mathbf{x}}\mathbf{u}.$ This type of notation will be nice when proving product rules and chain rules that come out looking similar to what we are familiar with for the scalar derivative.

### Vector-by-vector

Each of the previous two cases can be considered as an application of the derivative of a vector with respect to a vector, using a vector of size one appropriately. Similarly we will find that the derivatives involving matrices will reduce to derivatives involving vectors in a corresponding way.

The derivative of a vector function (a vector whose components are functions) $\mathbf{y} = \begin{bmatrix} y_1 \\ y_2 \\ \vdots \\ y_m \\ \end{bmatrix}$, with respect to an input vector, $\mathbf{x} = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \\ \end{bmatrix}$, is written (in numerator layout notation) as

$\frac{\partial \mathbf{y}}{\partial \mathbf{x}} = \begin{bmatrix} \frac{\partial y_1}{\partial x_1} & \frac{\partial y_1}{\partial x_2} & \cdots & \frac{\partial y_1}{\partial x_n}\\ \frac{\partial y_2}{\partial x_1} & \frac{\partial y_2}{\partial x_2} & \cdots & \frac{\partial y_2}{\partial x_n}\\ \vdots & \vdots & \ddots & \vdots\\ \frac{\partial y_m}{\partial x_1} & \frac{\partial y_m}{\partial x_2} & \cdots & \frac{\partial y_m}{\partial x_n}\\ \end{bmatrix}.$

In vector calculus, the derivative of a vector function y with respect to a vector x whose components represent a space is known as the pushforward or differential, or the Jacobian matrix.

The pushforward along a vector function f with respect to vector v in Rm is given by $d\,\mathbf{f}(\mathbf{v}) = \frac{\partial \mathbf{f}}{\partial \mathbf{x}} \mathbf{v}.$

## Derivatives with matrices

There are two types of derivatives with matrices that can be organized into a matrix of the same size. These are the derivative of a matrix by a scalar and the derivative of a scalar by a matrix respectively. These can be useful in minimization problems found many areas of applied mathematics and have adopted the names tangent matrix and gradient matrix respectively after their analogs for vectors.

NOTE: The discussion in this section assumes the numerator layout convention for pedagogical purposes. Some authors use different conventions. The section on layout conventions discusses this issue in greater detail. The identities given further down are presented in forms that can be used in conjunction with all common layout conventions.

### Matrix-by-scalar

The derivative of a matrix function Y by a scalar x is known as the tangent matrix and is given (in numerator layout notation) by

$\frac{\partial \mathbf{Y}}{\partial x} = \begin{bmatrix} \frac{\partial y_{11}}{\partial x} & \frac{\partial y_{12}}{\partial x} & \cdots & \frac{\partial y_{1n}}{\partial x}\\ \frac{\partial y_{21}}{\partial x} & \frac{\partial y_{22}}{\partial x} & \cdots & \frac{\partial y_{2n}}{\partial x}\\ \vdots & \vdots & \ddots & \vdots\\ \frac{\partial y_{m1}}{\partial x} & \frac{\partial y_{m2}}{\partial x} & \cdots & \frac{\partial y_{mn}}{\partial x}\\ \end{bmatrix}.$

### Scalar-by-matrix

The derivative of a scalar y function of a matrix X of independent variables, with respect to the matrix X, is given (in numerator layout notation) by

$\frac{\partial y}{\partial \mathbf{X}} = \begin{bmatrix} \frac{\partial y}{\partial x_{11}} & \frac{\partial y}{\partial x_{21}} & \cdots & \frac{\partial y}{\partial x_{p1}}\\ \frac{\partial y}{\partial x_{12}} & \frac{\partial y}{\partial x_{22}} & \cdots & \frac{\partial y}{\partial x_{p2}}\\ \vdots & \vdots & \ddots & \vdots\\ \frac{\partial y}{\partial x_{1q}} & \frac{\partial y}{\partial x_{2q}} & \cdots & \frac{\partial y}{\partial x_{pq}}\\ \end{bmatrix}.$

Notice that the indexing of the gradient with respect to X is transposed as compared with the indexing of X. Important examples of scalar functions of matrices include the trace of a matrix and the determinant.

In analog with vector calculus this derivative is often written as the following.

$\nabla_\mathbf{X} y(\mathbf{X}) = \frac{\partial y(\mathbf{X})}{\partial \mathbf{X}}$

Also in analog with vector calculus, the directional derivative of a scalar f(X) of a matrix X in the direction of matrix Y is given by

$\nabla_\mathbf{Y} f = \operatorname{tr} \left(\frac{\partial f}{\partial \mathbf{X}} \mathbf{Y}\right).$

It is the gradient matrix, in particular, that finds many uses in minimization problems in estimation theory, particularly in the derivation of the Kalman filter algorithm, which is of great importance in the field.

### Other matrix derivatives

The three types of derivatives that have not been considered are those involving vectors-by-matrices, matrices-by-vectors, and matrices-by-matrices. These are not as widely considered and a notation is not widely agreed upon. As for vectors, the other two types of higher matrix derivatives can be seen as applications of the derivative of a matrix by a matrix by using a matrix with one column in the correct place. For this reason, in this subsection we consider only how one can write the derivative of a matrix by another matrix.

The differential or the matrix derivative of a matrix function F(X) that maps from n×m matrices to p×q matrices, F : M(n,m) $\to$ M(p,q), is an element of M(p,q) ? M(m,n), a fourth-rank tensor (the reversal of m and n here indicates the dual space of M(n,m)). In short it is an m×n matrix each of whose entries is a p×q matrix.[citation needed]

$\frac{\partial\mathbf{F}} {\partial\mathbf{X}}= \begin{bmatrix} \frac{\partial\mathbf{F}}{\partial X_{1,1}} & \cdots & \frac{\partial \mathbf{F}}{\partial X_{n,1}}\\ \vdots & \ddots & \vdots\\ \frac{\partial\mathbf{F}}{\partial X_{1,m}} & \cdots & \frac{\partial \mathbf{F}}{\partial X_{n,m}}\\ \end{bmatrix},$

and note that each $\frac{\partial \mathbf{F}}{\partial \mathbf{X}_{ij}}$ is a p×q matrix defined as above. Note also that this matrix has its indexing transposed; m rows and n columns. The pushforward along F of an n×m matrix Y in M(n,m) is then

$d\mathbf{F}(\mathbf{Y}) = \operatorname{tr}\left(\frac{\partial\mathbf{F}} {\partial\mathbf{X}}\mathbf{Y}\right),$ as formal block matrices.

Note that this definition encompasses all of the preceding definitions as special cases.

According to Jan R. Magnus and Heinz Neudecker, the following notations are both unsuitable, as the determinant of the second resulting matrix would have "no interpretation" and "a useful chain rule does not exist" if these notations are being used:[2]

Given $\phi$, a differentiable function of an $n \times m$ matrix $\mathbf X = (x_{i, j})$,
$\frac{\partial \mathbf\phi(\mathbf X)} {\partial \mathbf{X}}= \begin{bmatrix} \frac{\partial \mathbf\phi}{\partial x_{1,1}} & \cdots & \frac{\partial \mathbf\phi}{\partial x_{1,q}}\\ \vdots & \ddots & \vdots\\ \frac{\partial \mathbf\phi}{\partial x_{n,1}} & \cdots & \frac{\partial \mathbf\phi}{\partial x_{n,q}}\\ \end{bmatrix}$
Given $\mathbf F = (f_{s,t})$, a differentiable $m \times n$ function of an $n \times m$ matrix $\mathbf X$,
$\frac{\partial \mathbf F (\mathbf X)} {\partial \mathbf{X}}= \begin{bmatrix} \frac{\partial f_{1,1}}{\partial \mathbf X} & \cdots & \frac{\partial f_{1,p}}{\partial \mathbf X}\\ \vdots & \ddots & \vdots\\ \frac{\partial f_{m,1}}{\partial \mathbf X} & \cdots & \frac{\partial f_{m,p}}{\partial \mathbf X}\\ \end{bmatrix}$

The Jacobian matrix, according to Magnus and Neudecker,[2] is

$\mathrm D\, \mathbf F\left(\mathbf X\right) = \frac{\partial\, \mathrm{vec}\ \mathbf F\left(\mathbf X\right)}{\partial\left(\mathrm{vec}\ \mathbf X\right)^{\prime}}.$

## Layout conventions

This section discusses the similarities and differences between notational conventions that are used in the various fields that take advantage of matrix calculus. Although there are largely two consistent conventions, some authors find it convenient to mix the two conventions in forms that are discussed below. After this section equations will be listed in both competing forms separately.

The fundamental issue is that the derivative of a vector with respect to a vector, i.e. $\frac{\partial \mathbf{y}}{\partial \mathbf{x}}$, is often written in two competing ways. If the numerator y is of size m and the denominator x of size n, then the result can be laid out as either an m×n matrix or n×m matrix, i.e. the elements of y laid out in columns and the elements of x laid out in rows, or vice versa. This leads to the following possibilities:

1. Numerator layout, i.e. lay out according to y and xT (i.e. contrarily to x). This is sometimes known as the Jacobian formulation.
2. Denominator layout, i.e. lay out according to yT and x (i.e. contrarily to y). This is sometimes known as the Hessian formulation. Some authors term this layout the gradient, in distinction to the Jacobian (numerator layout), which is its transpose. (However, "gradient" more commonly means the derivative $\frac{\partial y}{\partial \mathbf{x}},$ regardless of layout.)
3. A third possibility sometimes seen is to insist on writing the derivative as $\frac{\partial \mathbf{y}}{\partial \mathbf{x}'},$ (i.e. the derivative is taken with respect to the transpose of x) and follow the numerator layout. This makes it possible to claim that the matrix is laid out according to both numerator and denominator. In practice this produces results the same as the numerator layout.

When handling the gradient $\frac{\partial y}{\partial \mathbf{x}}$ and the opposite case $\frac{\partial \mathbf{y}}{\partial x},$ we have the same issues. To be consistent, we should do one of the following:

1. If we choose numerator layout for $\frac{\partial \mathbf{y}}{\partial \mathbf{x}},$ we should lay out the gradient $\frac{\partial y}{\partial \mathbf{x}}$ as a row vector, and $\frac{\partial \mathbf{y}}{\partial x}$ as a column vector.
2. If we choose denominator layout for $\frac{\partial \mathbf{y}}{\partial \mathbf{x}},$ we should lay out the gradient $\frac{\partial y}{\partial \mathbf{x}}$ as a column vector, and $\frac{\partial \mathbf{y}}{\partial x}$ as a row vector.
3. In the third possibility above, we write $\frac{\partial y}{\partial \mathbf{x}'}$ and $\frac{\partial \mathbf{y}}{\partial x},$ and use numerator layout.

Not all math textbooks and papers are consistent in this respect throughout the entire paper. That is, sometimes different conventions are used in different contexts within the same paper. For example, some choose denominator layout for gradients (laying them out as column vectors), but numerator layout for the vector-by-vector derivative $\frac{\partial \mathbf{y}}{\partial \mathbf{x}}.$

Similarly, when it comes to scalar-by-matrix derivatives $\frac{\partial y}{\partial \mathbf{X}}$ and matrix-by-scalar derivatives $\frac{\partial \mathbf{Y}}{\partial x},$ then consistent numerator layout lays out according to Y and XT, while consistent denominator layout lays out according to YT and X. In practice, however, following a denominator layout for $\frac{\partial \mathbf{Y}}{\partial x},$ and laying the result out according to YT, is rarely seen because it makes for ugly formulas that do not correspond to the scalar formulas. As a result, the following layouts can often be found:

1. Consistent numerator layout, which lays out $\frac{\partial \mathbf{Y}}{\partial x}$ according to Y and $\frac{\partial y}{\partial \mathbf{X}}$ according to XT.
2. Mixed layout, which lays out $\frac{\partial \mathbf{Y}}{\partial x}$ according to Y and $\frac{\partial y}{\partial \mathbf{X}}$ according to X.
3. Use the notation $\frac{\partial y}{\partial \mathbf{X}'},$ with results the same as consistent numerator layout.

In the following formulas, we handle the five possible combinations $\frac{\partial y}{\partial \mathbf{x}}, \frac{\partial \mathbf{y}}{\partial x}, \frac{\partial \mathbf{y}}{\partial \mathbf{x}}, \frac{\partial y}{\partial \mathbf{X}}$ and $\frac{\partial \mathbf{Y}}{\partial x}$ separately. We also handle cases of scalar-by-scalar derivatives that involve an intermediate vector or matrix. (This can arise, for example, if a multi-dimensional parametric curve is defined in terms of a scalar variable, and then a derivative of a scalar function of the curve is taken with respect to the scalar that parameterizes the curve.) For each of the various combinations, we give numerator-layout and denominator-layout results, except in the cases above where denominator layout rarely occurs. In cases involving matrices where it makes sense, we give numerator-layout and mixed-layout results. As noted above, cases where vector and matrix denominators are written in transpose notation are equivalent to numerator layout with the denominators written without the transpose.

Keep in mind that various authors use different combinations of numerator and denominator layouts for different types of derivatives, and there is no guarantee that an author will consistently use either numerator or denominator layout for all types. Match up the formulas below with those quoted in the source to determine the layout used for that particular type of derivative, but be careful not to assume that derivatives of other types necessarily follow the same kind of layout.

When taking derivatives with an aggregate (vector or matrix) denominator in order to find a maximum or minimum of the aggregate, it should be kept in mind that using numerator layout will produce results that are transposed with respect to the aggregate. For example, in attempting to find the maximum likelihood estimate of a multivariate normal distribution using matrix calculus, if the domain is a kx1 column vector, then the result using the numerator layout will be in the form of a 1xk row vector. Thus, either the results should be transposed at the end or the denominator layout (or mixed layout) should be used.

Result of differentiating various kinds of aggregates with other kinds of aggregates
Scalar y Vector y (size m) Matrix Y (size m×n)
Notation Type Notation Type Notation Type
Scalar x $\frac{\partial y}{\partial x}$ scalar $\frac{\partial \mathbf{y}}{\partial x}$ (numerator layout) size-m column vector

(denominator layout) size-m row vector

$\frac{\partial \mathbf{Y}}{\partial x}$ (numerator layout) m×n matrix
Vector x (size n) $\frac{\partial y}{\partial \mathbf{x}}$ (numerator layout) size-n row vector

(denominator layout) size-n column vector

$\frac{\partial \mathbf{y}}{\partial \mathbf{x}}$ (numerator layout) m×n matrix

(denominator layout) n×m matrix

$\frac{\partial \mathbf{Y}}{\partial \mathbf{x}}$  ?
Matrix X (size p×q) $\frac{\partial y}{\partial \mathbf{X}}$ (numerator layout) q×p matrix

(denominator layout) p×q matrix

$\frac{\partial \mathbf{y}}{\partial \mathbf{X}}$  ? $\frac{\partial \mathbf{Y}}{\partial \mathbf{X}}$  ?

The results of operations will be transposed when switching between numerator-layout and denominator-layout notation.

### Numerator-layout notation

Using numerator-layout notation, we have:[1]

$\frac{\partial y}{\partial \mathbf{x}} = \left[ \frac{\partial y}{\partial x_1} \frac{\partial y}{\partial x_2} \cdots \frac{\partial y}{\partial x_n} \right].$
$\frac{\partial \mathbf{y}}{\partial x} = \begin{bmatrix} \frac{\partial y_1}{\partial x}\\ \frac{\partial y_2}{\partial x}\\ \vdots\\ \frac{\partial y_m}{\partial x}\\ \end{bmatrix}.$
$\frac{\partial \mathbf{y}}{\partial \mathbf{x}} = \begin{bmatrix} \frac{\partial y_1}{\partial x_1} & \frac{\partial y_1}{\partial x_2} & \cdots & \frac{\partial y_1}{\partial x_n}\\ \frac{\partial y_2}{\partial x_1} & \frac{\partial y_2}{\partial x_2} & \cdots & \frac{\partial y_2}{\partial x_n}\\ \vdots & \vdots & \ddots & \vdots\\ \frac{\partial y_m}{\partial x_1} & \frac{\partial y_m}{\partial x_2} & \cdots & \frac{\partial y_m}{\partial x_n}\\ \end{bmatrix}.$
$\frac{\partial y}{\partial \mathbf{X}} = \begin{bmatrix} \frac{\partial y}{\partial x_{11}} & \frac{\partial y}{\partial x_{21}} & \cdots & \frac{\partial y}{\partial x_{p1}}\\ \frac{\partial y}{\partial x_{12}} & \frac{\partial y}{\partial x_{22}} & \cdots & \frac{\partial y}{\partial x_{p2}}\\ \vdots & \vdots & \ddots & \vdots\\ \frac{\partial y}{\partial x_{1q}} & \frac{\partial y}{\partial x_{2q}} & \cdots & \frac{\partial y}{\partial x_{pq}}\\ \end{bmatrix}.$

The following definitions are only provided in numerator-layout notation:

$\frac{\partial \mathbf{Y}}{\partial x} = \begin{bmatrix} \frac{\partial y_{11}}{\partial x} & \frac{\partial y_{12}}{\partial x} & \cdots & \frac{\partial y_{1n}}{\partial x}\\ \frac{\partial y_{21}}{\partial x} & \frac{\partial y_{22}}{\partial x} & \cdots & \frac{\partial y_{2n}}{\partial x}\\ \vdots & \vdots & \ddots & \vdots\\ \frac{\partial y_{m1}}{\partial x} & \frac{\partial y_{m2}}{\partial x} & \cdots & \frac{\partial y_{mn}}{\partial x}\\ \end{bmatrix}.$
$d\mathbf{X} = \begin{bmatrix} dx_{11} & dx_{12} & \cdots & dx_{1n}\\ dx_{21} & dx_{22} & \cdots & dx_{2n}\\ \vdots & \vdots & \ddots & \vdots\\ dx_{m1} & dx_{m2} & \cdots & dx_{mn}\\ \end{bmatrix}.$

### Denominator-layout notation

Using denominator-layout notation, we have:[3]

$\frac{\partial y}{\partial \mathbf{x}} = \begin{bmatrix} \frac{\partial y}{\partial x_1}\\ \frac{\partial y}{\partial x_2}\\ \vdots\\ \frac{\partial y}{\partial x_n}\\ \end{bmatrix}.$
$\frac{\partial \mathbf{y}}{\partial x} = \left[ \frac{\partial y_1}{\partial x} \frac{\partial y_2}{\partial x} \cdots \frac{\partial y_m}{\partial x} \right].$
$\frac{\partial \mathbf{y}}{\partial \mathbf{x}} = \begin{bmatrix} \frac{\partial y_1}{\partial x_1} & \frac{\partial y_2}{\partial x_1} & \cdots & \frac{\partial y_m}{\partial x_1}\\ \frac{\partial y_1}{\partial x_2} & \frac{\partial y_2}{\partial x_2} & \cdots & \frac{\partial y_m}{\partial x_2}\\ \vdots & \vdots & \ddots & \vdots\\ \frac{\partial y_1}{\partial x_n} & \frac{\partial y_2}{\partial x_n} & \cdots & \frac{\partial y_m}{\partial x_n}\\ \end{bmatrix}.$
$\frac{\partial y}{\partial \mathbf{X}} = \begin{bmatrix} \frac{\partial y}{\partial x_{11}} & \frac{\partial y}{\partial x_{12}} & \cdots & \frac{\partial y}{\partial x_{1q}}\\ \frac{\partial y}{\partial x_{21}} & \frac{\partial y}{\partial x_{22}} & \cdots & \frac{\partial y}{\partial x_{2q}}\\ \vdots & \vdots & \ddots & \vdots\\ \frac{\partial y}{\partial x_{p1}} & \frac{\partial y}{\partial x_{p2}} & \cdots & \frac{\partial y}{\partial x_{pq}}\\ \end{bmatrix}.$

## Identities

As noted above, in general, the results of operations will be transposed when switching between numerator-layout and denominator-layout notation.

To help make sense of all the identities below, keep in mind the most important rules: the chain rule, product rule and sum rule. The sum rule applies universally, and the product rule applies in most of the cases below, provided that the order of matrix products is maintained, since matrix products are not commutative. The chain rule applies in some of the cases, but unfortunately does not apply in matrix-by-scalar derivatives or scalar-by-matrix derivatives (in the latter case, mostly involving the trace operator applied to matrices). In the latter case, the product rule can't quite be applied directly, either, but the equivalent can be done with a bit more work using the differential identities.

### Vector-by-vector identities

This is presented first because all of the operations that apply to vector-by-vector differentiation apply directly to vector-by-scalar or scalar-by-vector differentiation simply by reducing the appropriate vector in the numerator or denominator to a scalar.

Identities: vector-by-vector $\frac{\partial \mathbf{y}}{\partial \mathbf{x}}$
Condition Expression Numerator layout, i.e. by y and xT Denominator layout, i.e. by yT and x
a is not a function of x $\frac{\partial \mathbf{a}}{\partial \mathbf{x}} =$ $\mathbf{0}$
$\frac{\partial \mathbf{x}}{\partial \mathbf{x}} =$ $\mathbf{I}$
A is not a function of x $\frac{\partial \mathbf{A}\mathbf{x}}{\partial \mathbf{x}} =$ $\mathbf{A}$ $\mathbf{A}^\top$
A is not a function of x $\frac{\partial \mathbf{x}^\top \mathbf{A}}{\partial \mathbf{x}} =$ $\mathbf{A}^\top$ $\mathbf{A}$
a is not a function of x,
u = u(x)
$\frac{\partial a\mathbf{u}}{\partial\, \mathbf{x}} =$ $a\frac{\partial \mathbf{u}}{\partial \mathbf{x}}$
a = a(x), u = u(x) $\frac{\partial a\mathbf{u}}{\partial \mathbf{x}} =$ $a \frac{\partial \mathbf{u}}{\partial \mathbf{x}} + \mathbf{u}\frac{\partial a}{\partial \mathbf{x}}$ $a\frac{\partial \mathbf{u}}{\partial \mathbf{x}} + \frac{\partial a}{\partial \mathbf{x}} \mathbf{u}^\top$
A is not a function of x,
u = u(x)
$\frac{\partial \mathbf{A}\mathbf{u}}{\partial \mathbf{x}} =$ $\mathbf{A}\frac{\partial \mathbf{u}}{\partial \mathbf{x}}$ $\frac{\partial \mathbf{u}}{\partial \mathbf{x}}\mathbf{A}^\top$
u = u(x), v = v(x) $\frac{\partial (\mathbf{u} + \mathbf{v})}{\partial \mathbf{x}} =$ $\frac{\partial \mathbf{u}}{\partial \mathbf{x}} + \frac{\partial \mathbf{v}}{\partial \mathbf{x}}$
u = u(x) $\frac{\partial \mathbf{g(u)}}{\partial \mathbf{x}} =$ $\frac{\partial \mathbf{g(u)}}{\partial \mathbf{u}} \frac{\partial \mathbf{u}}{\partial \mathbf{x}}$ $\frac{\partial \mathbf{u}}{\partial \mathbf{x}} \frac{\partial \mathbf{g(u)}}{\partial \mathbf{u}}$
u = u(x) $\frac{\partial \mathbf{f(g(u))}}{\partial \mathbf{x}} =$ $\frac{\partial \mathbf{f(g)}}{\partial \mathbf{g}} \frac{\partial \mathbf{g(u)}}{\partial \mathbf{u}} \frac{\partial \mathbf{u}}{\partial \mathbf{x}}$ $\frac{\partial \mathbf{u}}{\partial \mathbf{x}} \frac{\partial \mathbf{g(u)}}{\partial \mathbf{u}} \frac{\partial \mathbf{f(g)}}{\partial \mathbf{g}}$

### Scalar-by-vector identities

The fundamental identities are placed above the thick black line.

Identities: scalar-by-vector $\frac{\partial y}{\partial \mathbf{x}} = \nabla_\mathbf{x} y$
Condition Expression Numerator layout,
i.e. by xT; result is row vector
Denominator layout,
i.e. by x; result is column vector
a is not a function of x $\frac{\partial a}{\partial \mathbf{x}} =$ $\mathbf{0}^\top$ [4] $\mathbf{0}$ [4]
a is not a function of x,
u = u(x)
$\frac{\partial au}{\partial \mathbf{x}} =$ $a\frac{\partial u}{\partial \mathbf{x}}$
u = u(x), v = v(x) $\frac{\partial (u+v)}{\partial \mathbf{x}} =$ $\frac{\partial u}{\partial \mathbf{x}} + \frac{\partial v}{\partial \mathbf{x}}$
u = u(x), v = v(x) $\frac{\partial uv}{\partial \mathbf{x}} =$ $u\frac{\partial v}{\partial \mathbf{x}} + v\frac{\partial u}{\partial \mathbf{x}}$
u = u(x) $\frac{\partial g(u)}{\partial \mathbf{x}} =$ $\frac{\partial g(u)}{\partial u} \frac{\partial u}{\partial \mathbf{x}}$
u = u(x) $\frac{\partial f(g(u))}{\partial \mathbf{x}} =$ $\frac{\partial f(g)}{\partial g} \frac{\partial g(u)}{\partial u} \frac{\partial u}{\partial \mathbf{x}}$
u = u(x), v = v(x) $\frac{\partial (\mathbf{u} \cdot \mathbf{v})}{\partial \mathbf{x}} = \frac{\partial \mathbf{u}^\top \mathbf{v}}{\partial \mathbf{x}} =$ $\mathbf{u}^\top\frac{\partial \mathbf{v}}{\partial \mathbf{x}} + \mathbf{v}^\top\frac{\partial \mathbf{u}}{\partial \mathbf{x}}$
• assumes numerator layout of $\frac{\partial \mathbf{u}}{\partial \mathbf{x}}, \frac{\partial \mathbf{v}}{\partial \mathbf{x}}$
$\frac{\partial \mathbf{u}}{\partial \mathbf{x}}\mathbf{v} + \frac{\partial \mathbf{v}}{\partial \mathbf{x}}\mathbf{u}$
• assumes denominator layout of $\frac{\partial \mathbf{u}}{\partial \mathbf{x}}, \frac{\partial \mathbf{v}}{\partial \mathbf{x}}$
u = u(x), v = v(x),
A is not a function of x
$\frac{\partial (\mathbf{u} \cdot \mathbf{A}\mathbf{v})}{\partial \mathbf{x}} = \frac{\partial \mathbf{u}^\top\mathbf{A}\mathbf{v}}{\partial \mathbf{x}} =$ $\mathbf{u}^\top\mathbf{A}\frac{\partial \mathbf{v}}{\partial \mathbf{x}} + \mathbf{v}^\top \mathbf{A}^\top\frac{\partial \mathbf{u}}{\partial \mathbf{x}}$
• assumes numerator layout of $\frac{\partial \mathbf{u}}{\partial \mathbf{x}}, \frac{\partial \mathbf{v}}{\partial \mathbf{x}}$
$\frac{\partial \mathbf{u}}{\partial \mathbf{x}}\mathbf{A}\mathbf{v} + \frac{\partial \mathbf{v}}{\partial \mathbf{x}}\mathbf{A}^\top\mathbf{u}$
• assumes denominator layout of $\frac{\partial \mathbf{u}}{\partial \mathbf{x}}, \frac{\partial \mathbf{v}}{\partial \mathbf{x}}$
a is not a function of x $\frac{\partial (\mathbf{a}\cdot\mathbf{x})}{\partial \mathbf{x}} = \frac{\partial (\mathbf{x}\cdot\mathbf{a})}{\partial \mathbf{x}} =$

$\frac{\partial \mathbf{a}^\top\mathbf{x}}{\partial \mathbf{x}} = \frac{\partial \mathbf{x}^\top\mathbf{a}}{\partial \mathbf{x}} =$
$\mathbf{a}^\top$ $\mathbf{a}$
A is not a function of x
b is not a function of x
$\frac{\partial \mathbf{b}^\top\mathbf{A}\mathbf{x}}{\partial \mathbf{x}} =$ $\mathbf{b}^\top\mathbf{A}$ $\mathbf{A}^\top\mathbf{b}$
A is not a function of x $\frac{\partial \mathbf{x}^\top\mathbf{A}\mathbf{x}}{\partial \mathbf{x}} =$ $\mathbf{x}^\top(\mathbf{A} + \mathbf{A}^\top)$ $(\mathbf{A} + \mathbf{A}^\top)\mathbf{x}$
A is not a function of x
A is symmetric
$\frac{\partial \mathbf{x}^\top\mathbf{A}\mathbf{x}}{\partial \mathbf{x}} =$ $2\mathbf{x}^\top\mathbf{A}$ $2\mathbf{A}\mathbf{x}$
A is not a function of x $\frac{\partial^2 \mathbf{x}^\top\mathbf{A}\mathbf{x}}{\partial \mathbf{x}^2} =$ $\mathbf{A} + \mathbf{A}^\top$
A is not a function of x
A is symmetric
$\frac{\partial^2 \mathbf{x}^\top\mathbf{A}\mathbf{x}}{\partial \mathbf{x}^2} =$ $2\mathbf{A}$
$\frac{\partial (\mathbf{x} \cdot \mathbf{x})}{\partial \mathbf{x}} = \frac{\partial \mathbf{x}^\top\mathbf{x}}{\partial \mathbf{x}} =$ $2\mathbf{x}^\top$ $2\mathbf{x}$
a is not a function of x,
u = u(x)
$\frac{\partial (\mathbf{a} \cdot \mathbf{u})}{\partial \mathbf{x}} = \frac{\partial \mathbf{a}^\top\mathbf{u}}{\partial \mathbf{x}} =$ $\mathbf{a}^\top\frac{\partial \mathbf{u}}{\partial \mathbf{x}}$
• assumes numerator layout of $\frac{\partial \mathbf{u}}{\partial \mathbf{x}}$
$\frac{\partial \mathbf{u}}{\partial \mathbf{x}}\mathbf{a}$
• assumes denominator layout of $\frac{\partial \mathbf{u}}{\partial \mathbf{x}}$
a, b are not functions of x $\frac{\partial \; \textbf{a}^\top\textbf{x}\textbf{x}^\top\textbf{b}}{\partial \; \textbf{x}} =$ $\textbf{x}^\top(\textbf{a}\textbf{b}^\top + \textbf{b}\textbf{a}^\top)$ $(\textbf{a}\textbf{b}^\top + \textbf{b}\textbf{a}^\top)\textbf{x}$
A, b, C, D, e are not functions of x $\frac{\partial \; (\textbf{A}\textbf{x} + \textbf{b})^\top \textbf{C} (\textbf{D}\textbf{x} + \textbf{e}) }{\partial \; \textbf{x}} =$ $(\textbf{D}\textbf{x} + \textbf{e})^\top \textbf{C}^\top \textbf{A} + (\textbf{A}\textbf{x} + \textbf{b})^\top \textbf{C} \textbf{D}$ $\textbf{D}^\top \textbf{C}^\top (\textbf{A}\textbf{x} + \textbf{b}) + \textbf{A}^\top\textbf{C}(\textbf{D}\textbf{x} + \textbf{e})$
a is not a function of x $\frac{\partial \; \|\mathbf{x}-\mathbf{a}\|}{\partial \; \mathbf{x}} =$ $\frac{(\mathbf{x}-\mathbf{a})^\top}{\|\mathbf{x}-\mathbf{a}\|}$ $\frac{\mathbf{x}-\mathbf{a}}{\|\mathbf{x}-\mathbf{a}\|}$

### Vector-by-scalar identities

Identities: vector-by-scalar $\frac{\partial \mathbf{y}}{\partial x}$
Condition Expression Numerator layout, i.e. by y,
result is column vector
Denominator layout, i.e. by yT,
result is row vector
a is not a function of x $\frac{\partial \mathbf{a}}{\partial x} =$ $\mathbf{0}$[4]
a is not a function of x,
u = u(x)
$\frac{\partial a\mathbf{u}}{\partial x} =$ $a\frac{\partial \mathbf{u}}{\partial x}$
A is not a function of x,
u = u(x)
$\frac{\partial \mathbf{A}\mathbf{u}}{\partial x} =$ $\mathbf{A}\frac{\partial \mathbf{u}}{\partial x}$ $\frac{\partial \mathbf{u}}{\partial x}\mathbf{A}^\top$
u = u(x) $\frac{\partial \mathbf{u}^\top}{\partial x} =$ $\left(\frac{\partial \mathbf{u}}{\partial x}\right)^\top$
u = u(x), v = v(x) $\frac{\partial (\mathbf{u} + \mathbf{v})}{\partial x} =$ $\frac{\partial \mathbf{u}}{\partial x} + \frac{\partial \mathbf{v}}{\partial x}$
u = u(x), v = v(x) $\frac{\partial (\mathbf{u} \times \mathbf{v})}{\partial x} =$ $\mathbf{u} \times \frac{\partial \mathbf{v}}{\partial x} + \frac{\partial \mathbf{u}}{\partial x} \times \mathbf{v}$
u = u(x) $\frac{\partial \mathbf{g(u)}}{\partial x} =$ $\frac{\partial \mathbf{g(u)}}{\partial \mathbf{u}} \frac{\partial \mathbf{u}}{\partial x}$ $\frac{\partial \mathbf{u}}{\partial x} \frac{\partial \mathbf{g(u)}}{\partial \mathbf{u}}$
Assumes consistent matrix layout; see below.
u = u(x) $\frac{\partial \mathbf{f(g(u))}}{\partial x} =$ $\frac{\partial \mathbf{f(g)}}{\partial \mathbf{g}} \frac{\partial \mathbf{g(u)}}{\partial \mathbf{u}} \frac{\partial \mathbf{u}}{\partial x}$ $\frac{\partial \mathbf{u}}{\partial x} \frac{\partial \mathbf{g(u)}}{\partial \mathbf{u}} \frac{\partial \mathbf{f(g)}}{\partial \mathbf{g}}$
Assumes consistent matrix layout; see below.

NOTE: The formulas involving the vector-by-vector derivatives $\frac{\partial \mathbf{g(u)}}{\partial \mathbf{u}}$ and $\frac{\partial \mathbf{f(g)}}{\partial \mathbf{g}}$ (whose outputs are matrices) assume the matrices are laid out consistent with the vector layout, i.e. numerator-layout matrix when numerator-layout vector and vice versa; otherwise, transpose the vector-by-vector derivatives.

### Scalar-by-matrix identities

Note that exact equivalents of the scalar product rule and chain rule do not exist when applied to matrix-valued functions of matrices. However, the product rule of this sort does apply to the differential form (see below), and this is the way to derive many of the identities below involving the trace function, combined with the fact that the trace function allows transposing and cyclic permutation, i.e.:

${\rm tr}(\mathbf{A}) = {\rm tr}(\mathbf{A^\top})$
${\rm tr}(\mathbf{ABCD}) = {\rm tr}(\mathbf{BCDA}) = {\rm tr}(\mathbf{CDAB}) = {\rm tr}(\mathbf{DABC})$

For example, to compute $\frac{\partial {\rm tr}(\mathbf{AXBX^\top C})}{\partial \mathbf{X}}:$

\begin{align} d\, {\rm tr}(\mathbf{AXBX^\top C}) &= d\, {\rm tr}(\mathbf{CAXBX^\top}) = {\rm tr}(d(\mathbf{CAXBX^\top})) \\ &= {\rm tr}(\mathbf{CAX} d(\mathbf{BX^\top}) + d(\mathbf{CAX})\mathbf{BX^\top}) \\ &= {\rm tr}(\mathbf{CAX} d(\mathbf{BX^\top})) + {\rm tr}(d(\mathbf{CAX})\mathbf{BX^\top}) \\ &= {\rm tr}(\mathbf{CAXB} d(\mathbf{X^\top})) + {\rm tr}(\mathbf{CA}(d\mathbf{X})\mathbf{BX^\top}) \\ &= {\rm tr}(\mathbf{CAXB} (d\mathbf{X})^\top) + {\rm tr}(\mathbf{CA}(d\mathbf{X})\mathbf{BX^\top}) \\ &= {\rm tr}\left((\mathbf{CAXB} (d\mathbf{X})^\top)^\top\right) + {\rm tr}(\mathbf{CA}(d\mathbf{X})\mathbf{BX^\top}) \\ &= {\rm tr}((d\mathbf{X})\mathbf{B^\top X^\top A^\top C^\top}) + {\rm tr}(\mathbf{CA}(d\mathbf{X})\mathbf{BX^\top}) \\ &= {\rm tr}(\mathbf{B^\top X^\top A^\top C^\top}(d\mathbf{X})) + {\rm tr}(\mathbf{BX^\top}\mathbf{CA}(d\mathbf{X})) \\ &= {\rm tr}\left((\mathbf{B^\top X^\top A^\top C^\top} + \mathbf{BX^\top}\mathbf{CA})d\mathbf{X}\right) \end{align}

Therefore,

$\frac{\partial {\rm tr}(\mathbf{AXBX^\top C})}{\partial \mathbf{X}} = \mathbf{B^\top X^\top A^\top C^\top} + \mathbf{BX^\top}\mathbf{CA} .$

(For the last step, see the `Conversion from differential to derivative form' section.)

Identities: scalar-by-matrix $\frac{\partial y}{\partial \mathbf{X}}$
Condition Expression Numerator layout, i.e. by XT Denominator layout, i.e. by X
a is not a function of X $\frac{\partial a}{\partial \mathbf{X}} =$ $\mathbf{0}^\top$ [5] $\mathbf{0}$ [5]
a is not a function of X, u = u(X) $\frac{\partial au}{\partial \mathbf{X}} =$ $a\frac{\partial u}{\partial \mathbf{X}}$
u = u(X), v = v(X) $\frac{\partial (u+v)}{\partial \mathbf{X}} =$ $\frac{\partial u}{\partial \mathbf{X}} + \frac{\partial v}{\partial \mathbf{X}}$
u = u(X), v = v(X) $\frac{\partial uv}{\partial \mathbf{X}} =$ $u\frac{\partial v}{\partial \mathbf{X}} + v\frac{\partial u}{\partial \mathbf{X}}$
u = u(X) $\frac{\partial g(u)}{\partial \mathbf{X}} =$ $\frac{\partial g(u)}{\partial u} \frac{\partial u}{\partial \mathbf{X}}$
u = u(X) $\frac{\partial f(g(u))}{\partial \mathbf{X}} =$ $\frac{\partial f(g)}{\partial g} \frac{\partial g(u)}{\partial u} \frac{\partial u}{\partial \mathbf{X}}$
U = U(X) [6]    $\frac{\partial g(\mathbf{U})}{\partial X_{ij}} =$ ${\rm tr}\left( \frac{\partial g(\mathbf{U})}{\partial \mathbf{U}} \frac{\partial \mathbf{U}}{\partial X_{ij}}\right)$ ${\rm tr}\left( \left(\frac{\partial g(\mathbf{U})}{\partial \mathbf{U}}\right)^\top \frac{\partial \mathbf{U}}{\partial X_{ij}}\right)$
Both forms assume numerator layout for $\frac{\partial \mathbf{U}}{\partial X_{ij}},$

i.e. mixed layout if denominator layout for X is being used.

$\frac{\partial {\rm tr}(\mathbf{X})}{\partial \mathbf{X}} =$ $\mathbf{I}$
U = U(X), V = V(X) $\frac{\partial {\rm tr}(\mathbf{U}+\mathbf{V})}{\partial \mathbf{X}} =$ $\frac{\partial {\rm tr}(\mathbf{U})}{\partial \mathbf{X}} + \frac{\partial {\rm tr}(\mathbf{V})}{\partial \mathbf{X}}$
a is not a function of X,
U = U(X)
$\frac{\partial {\rm tr}(a\mathbf{U})}{\partial \mathbf{X}} =$ $a\frac{\partial {\rm tr}(\mathbf{U})}{\partial \mathbf{X}}$
g(X) is any polynomial with scalar coefficients, or any matrix function defined by an infinite polynomial series (e.g. eX, sin(X), cos(X), ln(X), etc. using a Taylor series); g(x) is the equivalent scalar function, g(x) is its derivative, and g(X) is the corresponding matrix function $\frac{\partial {\rm tr}(\mathbf{g(X)})}{\partial \mathbf{X}} =$ $\mathbf{g}'(\mathbf{X})$ $(\mathbf{g}'(\mathbf{X}))^\top$
A is not a function of X [7]    $\frac{\partial \top(\mathbf{AX})}{\partial \mathbf{X}} = \frac{\partial {\rm tr}(\mathbf{XA})}{\partial \mathbf{X}} =$ $\mathbf{A}$ $\mathbf{A}^\top$
A is not a function of X [6]    $\frac{\partial {\rm tr}(\mathbf{AX^\top})}{\partial \mathbf{X}} = \frac{\partial {\rm tr}(\mathbf{X^\top A})}{\partial \mathbf{X}} =$ $\mathbf{A}^\top$ $\mathbf{A}$
A is not a function of X [6]    $\frac{\partial {\rm tr}(\mathbf{X^\top AX})}{\partial \mathbf{X}} =$ $\mathbf{X}^\top(\mathbf{A}+\mathbf{A}^\top)$ $(\mathbf{A}+\mathbf{A}^\top)\mathbf{X}$
A is not a function of X [6]    $\frac{\partial {\rm tr}(\mathbf{X^{-1}A})}{\partial \mathbf{X}} =$ $-(\mathbf{X}^{-1})^\top\mathbf{A}(\mathbf{X}^{-1})^\top$ $-\mathbf{X}^{-1}\mathbf{A}^\top\mathbf{X}^{-1}$
A, B are not functions of X $\frac{\partial {\rm tr}(\mathbf{AXB})}{\partial \mathbf{X}} = \frac{\partial {\rm tr}(\mathbf{BAX})}{\partial \mathbf{X}} =$ $\mathbf{BA}$ $\mathbf{A^\top B^\top}$
A, B, C are not functions of X $\frac{\partial {\rm tr}(\mathbf{AXBX^\top C})}{\partial \mathbf{X}} =$ $\mathbf{BX^\top CA} + \mathbf{B^\top X^\top A^\top C^\top}$ $\mathbf{A^\top C^\top XB^\top} + \mathbf{CAXB}$
n is a positive integer [6]    $\frac{\partial {\rm tr}(\mathbf{X}^n)}{\partial \mathbf{X}} =$ $n\mathbf{X}^{n-1}$ $n(\mathbf{X}^{n-1})^\top$
A is not a function of X,
n is a positive integer
[6]    $\frac{\partial {\rm tr}(\mathbf{A}\mathbf{X}^n)}{\partial \mathbf{X}} =$ $\sum_{i=0}^{n-1} \mathbf{X}^i\mathbf{A}\mathbf{X}^{n-i-1}$ $\sum_{i=0}^{n-1} (\mathbf{X}^i\mathbf{A}\mathbf{X}^{n-i-1})^\top$
[6]    $\frac{\partial {\rm tr}(e^\mathbf{X})}{\partial \mathbf{X}} =$ $e^\mathbf{X}$ $(e^\mathbf{X})^\top$
[6]    $\frac{\partial {\rm tr}(\sin(\mathbf{X}))}{\partial \mathbf{X}} =$ $\cos(\mathbf{X})$ $(\cos(\mathbf{X}))^\top$
[8]    $\frac{\partial |\mathbf{X}|}{\partial \mathbf{X}} =$ $\operatorname{cofactor}(X)^\top = |\mathbf{X}|\mathbf{X}^{-1}$ $\operatorname{cofactor}(X) = |\mathbf{X}|(\mathbf{X}^{-1})^\top$
a is not a function of X [6]$\frac{\partial \ln |a\mathbf{X}|}{\partial \mathbf{X}} =$[9] $\mathbf{X}^{-1}$ $(\mathbf{X}^{-1})^\top$
A, B are not functions of X [6]     $\frac{\partial |\mathbf{AXB}|}{\partial \mathbf{X}} =$ $|\mathbf{AXB}|\mathbf{X}^{-1}$ $|\mathbf{AXB}|(\mathbf{X}^{-1})^\top$
n is a positive integer [6]    $\frac{\partial |\mathbf{X}^n|}{\partial \mathbf{X}} =$ $n|\mathbf{X}^n|\mathbf{X}^{-1}$ $n|\mathbf{X}^n|(\mathbf{X}^{-1})^\top$
(see pseudo-inverse) [6]      $\frac{\partial \ln |\mathbf{X}^\top\mathbf{X}|}{\partial \mathbf{X}} =$ $2\mathbf{X}^{+}$ $2(\mathbf{X}^{+})^\top$
(see pseudo-inverse) [6]     $\frac{\partial \ln |\mathbf{X}^\top\mathbf{X}|}{\partial \mathbf{X}^{+}} =$ $-2\mathbf{X}$ $-2\mathbf{X}^\top$
A is not a function of X,
X is square and invertible
$\frac{\partial |\mathbf{X^\top}\mathbf{A}\mathbf{X}|}{\partial \mathbf{X}} =$ $2|\mathbf{X^\top}\mathbf{A}\mathbf{X}|\mathbf{X}^{-1}$ $2|\mathbf{X^\top}\mathbf{A}\mathbf{X}|(\mathbf{X}^{-1})^\top$
A is not a function of X,
X is non-square,
A is symmetric
$\frac{\partial |\mathbf{X^\top}\mathbf{A}\mathbf{X}|}{\partial \mathbf{X}} =$ $2|\mathbf{X^\top}\mathbf{A}\mathbf{X}|(\mathbf{X^\top A^\top X})^{-1}\mathbf{X^\top A^\top}$ $2|\mathbf{X^\top}\mathbf{A}\mathbf{X}|\mathbf{AX}(\mathbf{X^\top AX})^{-1}$
A is not a function of X,
X is non-square,
A is non-symmetric
$\frac{\partial |\mathbf{X^\top}\mathbf{A}\mathbf{X}|}{\partial \mathbf{X}} =$ $|\mathbf{X^\top}\mathbf{A}\mathbf{X}|((\mathbf{X^\top AX})^{-1}\mathbf{X^\top A}$
$+ (\mathbf{X^\top A^\top X})^{-1}\mathbf{X^\top A^\top})$
$|\mathbf{X^\top}\mathbf{A}\mathbf{X}|(\mathbf{AX}(\mathbf{X^\top AX})^{-1}$
$+ \mathbf{A^\top X}(\mathbf{X^\top A^\top X})^{-1})$

### Matrix-by-scalar identities

Identities: matrix-by-scalar $\frac{\partial \mathbf{Y}}{\partial x}$
Condition Expression Numerator layout, i.e. by Y
U = U(x) $\frac{\partial a\mathbf{U}}{\partial x} =$ $a\frac{\partial \mathbf{U}}{\partial x}$
A, B are not functions of x,
U = U(x)
$\frac{\partial \mathbf{AUB}}{\partial x} =$ $\mathbf{A}\frac{\partial \mathbf{U}}{\partial x}\mathbf{B}$
U = U(x), V = V(x) $\frac{\partial (\mathbf{U}+\mathbf{V})}{\partial x} =$ $\frac{\partial \mathbf{U}}{\partial x} + \frac{\partial \mathbf{V}}{\partial x}$
U = U(x), V = V(x) $\frac{\partial (\mathbf{U}\mathbf{V})}{\partial x} =$ $\mathbf{U}\frac{\partial \mathbf{V}}{\partial x} + \frac{\partial \mathbf{U}}{\partial x}\mathbf{V}$
U = U(x), V = V(x) $\frac{\partial (\mathbf{U} \otimes \mathbf{V})}{\partial x} =$ $\mathbf{U} \otimes \frac{\partial \mathbf{V}}{\partial x} + \frac{\partial \mathbf{U}}{\partial x} \otimes \mathbf{V}$
U = U(x), V = V(x) $\frac{\partial (\mathbf{U} \circ \mathbf{V})}{\partial x} =$ $\mathbf{U} \circ \frac{\partial \mathbf{V}}{\partial x} + \frac{\partial \mathbf{U}}{\partial x} \circ \mathbf{V}$
U = U(x) $\frac{\partial \mathbf{U}^{-1}}{\partial x} =$ $-\mathbf{U}^{-1} \frac{\partial \mathbf{U}}{\partial x}\mathbf{U}^{-1}$
U = U(x,y) $\frac{\partial^2 \mathbf{U}^{-1}}{\partial x \partial y} =$ $\mathbf{U}^{-1}\left(\frac{\partial \mathbf{U}}{\partial x}\mathbf{U}^{-1}\frac{\partial \mathbf{U}}{\partial y} - \frac{\partial^2 \mathbf{U}}{\partial x \partial y} + \frac{\partial \mathbf{U}}{\partial y}\mathbf{U}^{-1}\frac{\partial \mathbf{U}}{\partial x}\right)\mathbf{U}^{-1}$
A is not a function of x, g(X) is any polynomial with scalar coefficients, or any matrix function defined by an infinite polynomial series (e.g. eX, sin(X), cos(X), ln(X), etc.); g(x) is the equivalent scalar function, g(x) is its derivative, and g(X) is the corresponding matrix function $\frac{\partial \, \mathbf{g}(x\mathbf{A})}{\partial x} =$ $\mathbf{A}\mathbf{g}'(x\mathbf{A}) = \mathbf{g}'(x\mathbf{A})\mathbf{A}$
A is not a function of x $\frac{\partial e^{x\mathbf{A}}}{\partial x} =$ $\mathbf{A}e^{x\mathbf{A}} = e^{x\mathbf{A}}\mathbf{A}$

Further see Derivative of the exponential map.

### Scalar-by-scalar identities

#### With vectors involved

Identities: scalar-by-scalar, with vectors involved
Condition Expression Any layout (assumes dot product ignores row vs. column layout)
u = u(x) $\frac{\partial g(\mathbf{u})}{\partial x} =$ $\frac{\partial g(\mathbf{u})}{\partial \mathbf{u}} \cdot \frac{\partial \mathbf{u}}{\partial x}$
u = u(x), v = v(x) $\frac{\partial (\mathbf{u} \cdot \mathbf{v})}{\partial x} =$ $\mathbf{u} \cdot \frac{\partial \mathbf{v}}{\partial x} + \frac{\partial \mathbf{u}}{\partial x} \cdot \mathbf{v}$

#### With matrices involved

Identities: scalar-by-scalar, with matrices involved[6]
Condition Expression Consistent numerator layout,
i.e. by Y and XT
Mixed layout,
i.e. by Y and X
U = U(x) $\frac{\partial |\mathbf{U}|}{\partial x} =$ $|\mathbf{U}|{\rm tr}\left(\mathbf{U}^{-1}\frac{\partial \mathbf{U}}{\partial x}\right)$
U = U(x) $\frac{\partial \ln|\mathbf{U}|}{\partial x} =$ ${\rm tr}\left(\mathbf{U}^{-1}\frac{\partial \mathbf{U}}{\partial x}\right)$
U = U(x) $\frac{\partial^2 |\mathbf{U}|}{\partial x^2} =$ $|\mathbf{U}|\left[{\rm tr}\left(\mathbf{U}^{-1}\frac{\partial^2 \mathbf{U}}{\partial x^2}\right) + \left({\rm tr}\left(\mathbf{U}^{-1}\frac{\partial \mathbf{U}}{\partial x}\right)\right)^2-{\rm tr}\left(\left(\mathbf{U}^{-1}\frac{\partial \mathbf{U}}{\partial x}\right)\left(\mathbf{U}^{-1}\frac{\partial \mathbf{U}}{\partial x}\right)\right)\right]$
U = U(x) $\frac{\partial g(\mathbf{U})}{\partial x} =$ ${\rm tr}\left( \frac{\partial g(\mathbf{U})}{\partial \mathbf{U}} \frac{\partial \mathbf{U}}{\partial x}\right)$ ${\rm tr}\left( \left(\frac{\partial g(\mathbf{U})}{\partial \mathbf{U}}\right)^\top \frac{\partial \mathbf{U}}{\partial x}\right)$
A is not a function of x, g(X) is any polynomial with scalar coefficients, or any matrix function defined by an infinite polynomial series (e.g. eX, sin(X), cos(X), ln(X), etc.); g(x) is the equivalent scalar function, g(x) is its derivative, and g(X) is the corresponding matrix function. $\frac{\partial \, {\rm tr}(\mathbf{g}(x\mathbf{A}))}{\partial x} =$ ${\rm tr}(\mathbf{A}\mathbf{g}'(x\mathbf{A}))$
A is not a function of x $\frac{\partial \, {\rm tr}(e^{x\mathbf{A}})}{\partial x} =$ ${\rm tr}(\mathbf{A}e^{x\mathbf{A}})$

### Identities in differential form

It is often easier to work in differential form and then convert back to normal derivatives. This only works well using the numerator layout.

Differential identities: scalar involving matrix [1][6]
Condition Expression Result (numerator layout)
$d({\rm tr}(\mathbf{X})) =$ ${\rm tr}(d\mathbf{X})$
$d(|\mathbf{X}|) =$ $|\mathbf{X}|{\rm tr}(\mathbf{X}^{-1}d\mathbf{X})$
$d(\ln|\mathbf{X}|) =$ ${\rm tr}(\mathbf{X}^{-1}d\mathbf{X})$
Differential identities: matrix [1][6]
Condition Expression Result (numerator layout)
A is not a function of X $d(\mathbf{A}) =$ $0$
a is not a function of X $d(a\mathbf{X}) =$ $a\,d\mathbf{X}$
$d(\mathbf{X}+\mathbf{Y}) =$ $d\mathbf{X}+d\mathbf{Y}$
$d(\mathbf{X}\mathbf{Y}) =$ $(d\mathbf{X})\mathbf{Y}+\mathbf{X}(d\mathbf{Y})$
(Kronecker product) $d(\mathbf{X} \otimes \mathbf{Y}) =$ $(d\mathbf{X})\otimes\mathbf{Y}+\mathbf{X}\otimes(d\mathbf{Y})$
(Hadamard product) $d(\mathbf{X} \circ \mathbf{Y}) =$ $(d\mathbf{X})\circ\mathbf{Y}+\mathbf{X}\circ(d\mathbf{Y})$
$d(\mathbf{X}^\top) =$ $(d\mathbf{X})^\top$
(conjugate transpose) $d(\mathbf{X}^{\rm H}) =$ $(d\mathbf{X})^{\rm H}$

To convert to normal derivative form, first convert it to one of the following canonical forms, and then use these identities:

Conversion from differential to derivative form [1]
Canonical differential form Equivalent derivative form
$dy = a\,dx$ $\frac{dy}{dx} = a$
$dy = \mathbf{a}\,d\mathbf{x}$ $\frac{dy}{d\mathbf{x}} = \mathbf{a}$
$dy = {\rm tr}(\mathbf{A}\,d\mathbf{X})$ $\frac{dy}{d\mathbf{X}} = \mathbf{A}$
$d\mathbf{y} = \mathbf{a}\,dx$ $\frac{d\mathbf{y}}{dx} = \mathbf{a}$
$d\mathbf{y} = \mathbf{A}\,d\mathbf{x}$ $\frac{d\mathbf{y}}{d\mathbf{x}} = \mathbf{A}$
$d\mathbf{Y} = \mathbf{A}\,dx$ $\frac{d\mathbf{Y}}{dx} = \mathbf{A}$

4. ^ a b c Here, $\mathbf{0}$ refers to a column vector of all 0's, of size n, where n is the length of x.
5. ^ a b Here, $\mathbf{0}$ refers to a matrix of all 0's, of the same shape as X.
6. Petersen, Kaare Brandt and Michael Syskind Pedersen. The Matrix Cookbook. November 14, 2008. http://matrixcookbook.com. [3] This book uses a mixed layout, i.e. by Y in $\frac{\partial \mathbf{Y}}{\partial x},$ by X in $\frac{\partial y}{\partial \mathbf{X}}.$
$\frac{d\,\ln au}{dx} = \frac{1}{au}\frac{d(au)}{dx} = \frac{1}{au}a\frac{du}{dx} = \frac{1}{u}\frac{du}{dx} = \frac{d\,\ln u}{dx}.$