Matrix Calculus#


Revised

17 Jun 2023


.

scalar

vector

matrix

scalar

yx

yx

Yx

vector

yx

yx

matrix

yX

scalar-by-scalar#

derivative of a scalar (function) wrt a scalar

[example]

f(x)=kxdfdx=k

scalar-by-vector#

derivative of a scalar (function) wrt a vector

x=[x1xn]yx=[yx1yxn]

An example from the vector calculus is the gradient vector.

f(x)=fx=[fx1fxn]

vector-by-scalar#

derivative of a vector (function) wrt a scalar

y=[y1ym]yx=[y1xymx]

An example in the vector calculus is the tangent vector.

vector-by-vector#

derivative of a vector (function) wrt a vector

taking the derivative of a linear transformation (not “taking the derivative of a matrix”)

yx=[y1x1y1xnymx1ymxn]

Jacobian#

An example from the vector calculus is the Jacobian.

xAx=A#

[example]

f(x)=Ax=[1234][x1x2]=[x1+2x2=f1(x)3x1+4x2=f2(x)]fx=[f1x1f1x2f2x1f2x2]=[1234]=A

xxAx=2xA#

[example]

f(x)=xAx=[x1x2][a11a12a21a22][x1x2]=[x1x2][a11x1+a12x2a21x1+a22x2]=[x1(a11x1+a12x2)+x2(a21x1+a22x2)]=[a11x12+a12x1x2+a21x1x2+a22x22]=[a11x12+2ax1x2+a22x22=f1(x)]a12=a21for a symmetric matrixfx=[f1x1f1x2]=[2a11x1+2ax22ax1+2a22x2]=2[a11x1+ax2ax1+a22x2]=2(Ax)=2xA

matrix-by-scalar#

derivative of a matrix (function) wrt a scalar

this is called the tangent matrix

Yx=[y11xy1nxym1xymnx]

scalar-by-matrix#

derivative of a scalar (function) wrt a matrix

this is called the gradient matrix

important examples of scalar functions of matrices include the trace of a matrix and the determinant

yX=[yx11yxp1yx1qyxpq]


Resources#

  • [Y] ritvikmath. (09 Sep 2019). “Derivative of a Matrix : Data Science Basics”. YouTube.


Terms#

  • [W] Jacobian

  • [W] Matrix Calculus

  • [W] Tangent Vector