Matrix Calculus

Go to: Introduction, Notation, Index



Contents of Calculus Section

Notation

Derivatives

In the main part of this page we express results in terms of differentials rather than derivatives for two reasons: they avoid notational disagreements and they cope easily with the complex case. In most cases however, the differentials have been written in the form dY: = dY/dX dX: so that the corresponding derivative may be easily extracted.

Derivatives with respect to a real matrix

If X is p#q and Y is m#n, then dY: = dY/dX dX: where the derivative dY/dX is a large mn#pq matrix. If X and/or Y are column vectors or scalars, then the vectorization operator : has no effect and may be omitted. dY/dX is also called the Jacobian Matrix of Y: with respect to X: and det(dY/dX) is the corresponding Jacobian. The Jacobian occurs when changing variables in an integration: Integral(f(Y)dY:)=Integral(f(Y(X)) det(dY/dX) dX:).

Although they do not generalise so well, other authors use alternative notations for the cases when X and Y are both vectors or when one is a scalar. In particular:

Derivatives with respect to a complex matrix

If X is complex, we define the generalized complex and complex conjugate derivatives in terms of partial derivatives with respect to XR: and XI: and use the partial derivative symbol, ∂, to emphasise that these are not complete derivatives:

The properties of these derivatives are studied in the Wirtinger Calculus [R.4, R.9].

If X is complex then dY: = dY/dX dX: can only be generally true iff Y(X) is an analytic function (or equivalently a holomporphic function). This normally implies that Y(X) does not depend explicitly on XC or XH (e.g. y=xH and y=xHx are not analytic functions of x). The following are equivalent ways of saying that Y(X) is an analytic function of X:

Even for non-analytic functions we can treat X and XC (with XH=(XC)T) as distinct variables and write uniquely dY: = ∂Y/∂X dX: + ∂Y/∂XC dXC: provided that Y is analytic with respect to X and XC individually (or equivalently with respect to XR and XI individually).

We have the following relationships for both analytic and non-analytic functions Y(X):

Complex Gradient Vector

If f(X) is a real function of a complex matrix (or vector), X, then ∂f/∂XC= (∂f/∂X)C and we can define the complex-valued column vector grad(f(X)) = 2 (∂f/∂X)H = (∂f/XR+j ∂f/XI)T as the Complex Gradient Vector [R.9] with the properties listed below. If we use <-> to represent the vector mapping associated with the   Complex-to-Real isomporphism, and  X[m#n]: <-> y[2mn] where y is real, then grad(f(X)) <->  grad(f(y)) where the latter is the conventional grad function from vector calculus.

Real Constrained Minimization

Suppose f(X) is a scalar real-valued function of a real-valued matrix (or vector), X, and G(X) is a real-valued matrix (or vector or scalar) function of X. To minimize f(X) subject to G(X)=0, we use a real-valued Lagrange multiplier, K, of the same size as G, and minimize the Lagrangian, l(X)=f(X)+tr(KTG(X)), with respect to X with K chosen so that G(X)=0 at the minimum. Hence, according to whether G(X) is a matrix, vector or scalar value, any local minimum satisfies

If X is complex (but f(X) and G(X) are still real), we obtain an identical solution, but with partial derivatives instead of total derivatives. This follows because grad(l(X))=0 at the minimum and this is true if and only if ∂l/∂X=0.

Example: If f(x)=xTSx where S=ST and g(x)=aTx-1, then df/dx+kdg/dx=2xTS+kaT=0T which, transposed, gives 2Sx+ka=0 from which x=-0.5kS-1a. Substituting this into the constraint, g(x)=aTx-1=0, gives -0.5kaTS-1a = 1 from which k=-2(aTS-1a)-1. Substituting this back into the expression for x gives x = (aTS-1a)-1S-1a provided that aTS-1a≠0. For the specific case, S=I  and a=[1; 2], f(x) equals the squared distance from the origin. This is minimized when  x = (aTa)-1a = 0.2a = [0.2; 0.4] ; this is therefore the closest point to the origin that lies on the line aTx=1.

Complex Constrained Minimization

Suppose f(X) is a scalar real-valued analytic function of a complex matrix, X, and G(X) is a complex-valued matrix (or vector or scalar) function of X. To minimize f(X) subject to G(X)=0, we use a complex-valued Lagrange multiplier, K, of the same size as G, and minimize the Lagrangian,  l(X)=f(X)+2tr(KHG(X))R = f(X)+tr(KHG(X))+tr(KTG(X)C), subject to G(X)=0. Hence, according to whether G(X) is a matrix, vector or scalar value, any local minimum satisfies

This is equivalent to treating the GR(X)=0 and GI(X)=0 as independent real-valued constraints with KR and KI the corresponding Lagrange multipliers. This follows since 2tr(KHG(X))R=2tr((KH)R GR(X) - (KH)I GI(X)) = 2tr((KR)T GR(X)) +2tr((KI)T GI(X)). Note that some authors define the Lagrange multiplier, K, to be the complex conjugate of the one defined above and/or multiply its value by 2.

Example: Suppose we wish to minimize f(x)=xHx subject to g(x)=aHx+bTxC-1=0. Then ∂f/∂x+kCg/∂x+k∂gC/∂x = xH+kCaH+kbH = 0T from which x = -(ka+kCb). Substituting this into the constraint gives, aH(ka+kCb)+bT(kCaC+kbC) = k(aHa+bHb)+2kCaHb = -1. Eliminating kC between this equation and its conjugate gives k((|a|2+|b|2)2-4|aHb|2)=2aHb-|a|2-|b|2 from which k=(2aHb-|a|2-|b|2)/((|a|2+|b|2)2-4|aHb|2) and x=((|a|2+|b|2-2aHb)a+(|a|2+|b|2-2bHa)b)/((|a|2+|b|2)2-4|aHb|2) provided that the dnominator is non-zero. For the specific case, a=[1; 1] and b=[-1; j], we get k=-0.75+0.25j and x=[-0.5j; 0.5+05j] giving f(x)=0.75.

Basic Properties

Differentials of Linear Functions

Differentials of Quadratic Products

Differentials of Cubic Products

Differentials of Inverses

Differentials of Trace

Note: matrix dimensions must result in an n*n argument for tr().

Trace Minimization

In the following expressions M# denotes the inverse of M or, if M is singular, any generalized inverse (including the pseudoinverse).

Differentials of Determinant

Note: matrix dimensions must result in an n#n argument for det(). Some of the expressions below involve inverses: these forms apply only if the quantity being inverted is square and non-singular; alternative forms involving the adjoint, ADJ(), do not have the non-singular requirement.

Jacobian

 dY/dX is called the Jacobian Matrix of Y: with respect to X: and JX(Y)=det(dY/dX) is the corresponding Jacobian. The Jacobian occurs when changing variables in an integration: Integral(f(Y)dY:)=Integral(f(Y(X)) det(dY/dX) dX:).

Hessian matrix

If f is a real function of x then the Hermitian matrix Hx  f = (d/dx (df/dx)H)T  is the Hessian matrix of f(x). A value of x for which grad f(x) = 0 corresponds to a minimum, maximum or saddle point according to whether Hx f is positive definite, negative definite or indefinite.


This page is part of The Matrix Reference Manual. Copyright © 1998-2026 Mike Brookes, Imperial College, London, UK. See the file gfl.html for copying instructions. Please send any comments or suggestions to "mike.brookes" at "imperial.ac.uk".
Updated: $Id: calculus.html 11291 2021-01-05 18:26:10Z dmb $