32  Linear Algebra

32.1 Vector multiplication

Consider a vector of this form,

yn×1=(y1yiyn), then yn×1yn×1=yn×1y1×n=yn×n=(y12y1yiy1ynyiy1yi2yiynyny1ynyiyn2), and yn×1xn×1=y1×nyn×1=i=1nyi2=y1×1.

32.2 Matrix multiplication

Consider a matrix of this form,

Xn×k=(x11x1jx1kx11xijxikxn1xnjxk), then Mk×k=Xn×kXn×k=(i=1nxi12i=1nxi1xiji=1nxi1xiki=1nxijxi1i=1nxij2i=1nxijxiki=1nxikxi1i=1nxikxiji=1nxik2), and mk×1=Xn×kyn×1=(i=1nxi1yii=1nxijyii=1nxikyi).

32.3 Special matrices

32.3.1 Basis vector

(32.1)ep=(100). The standard basis vector of length p with 1 in the first position and 0 elsewhere.

32.3.2 Matrix of ones

In mathematics, a matrix of ones (also called an all-ones matrix) is a matrix where every entry equals 1, i.e. (32.2)J2=(1111)J3=(111111111)J3,2=(111111)J2,3=(111111) In general, When two indices are provided, e.g., J3,2, the first indicates the number of rows and the second the number of columns. When only one index is given, e.g., J3, it denotes a square matrix of size 3×3. Some basic matrix operations include:

  • Jn,1J1,n=Jn
  • J1,nJn,1=J1=1
Matrix of ones
J_n <- function(i, j){
  matrix(1, nrow = i, ncol = j)
}

32.3.3 Identity matrix

In linear algebra, the identity matrix of size n is the n×n square matrix with ones on the main diagonal and zeros elsewhere, i.e.  (32.3)I1=(1),I2=(1001),I3=(100010001),I3=(1000010000100001).

Identity matrix
I_n <- function(i, j){
  diag(1, nrow = i, ncol = j) 
}

32.4 Determinant

The determinant is a scalar value that can be computed from a square matrix. It provides important information about the matrix, such as whether it is invertible, its volume-scaling factor in linear transformations, and the linear dependence of its rows or columns. For a matrix ARn×n, the determinant is denoted det(A). Consider two matrices An×n and Bn×n, then the determinant satisfies some properties.

  1. Scalar: adet(A)=andet(A) for aR.
  2. Transpose: det(A)=det(A).
  3. Multiplication: det(AB)=det(A)det(B).
  4. Inverse: det(A1)=1det(A).
  5. Rank: if
    • det(A)0 then rank(A)=max=n.
    • det(A)=0 then rank(A)<max=n.

The determinant of an n×n matrix can be computed by expanding along any row or column. Expanding along the i-th row gives: (32.4)det(A)=j=1n(1)i+jaijdet(Mij). where Mij is the sub-matrix without the i-th row and the j-th column. For example considering a 2×2 matrix, the determinant simplifies to a well-known formula: (32.5)A=(abcd)det(A)=adbc.

Let’s consider a generic 3×3 matrix, i.e. A=(a11a12a13a21a22a23a31a32a33), then, let’s fix the row i=1 and develop the Laplace expansion (), i.e. (32.6)det(A)=(1)1+1a11M11+(1)1+2a12M12+(1)1+3a13M13==a11M11a12M12+a13M13 where the sub-matrices M11, M12 and M13 read explicitly as: M11=(a22a23a32a33),M12=(a21a23a31a33),M13=(a21a22a31a32). Then, the determinant of 2×2 matrices is easily computable as: (32.7)det(M11)=det(a22a23a32a33)=a22a33a23a32det(M12)=det(a21a23a31a33)=a21a33a23a31det(M13)=det(a21a22a31a32)=a21a32a22a31 Finally, coming back to and substituting the result in one obtain: det(A)=a11(a22a33a23a32)a12(a21a33a23a31)+a13(a21a32a22a31).

32.5 Trace

The trace of a square matrix ARn×n is the sum of its diagonal elements. It is also equal to the sum of the eigenvalues λi of A, counted with algebraic multiplicity, i.e. (32.8)tr(A)=i=1naii=i=1nλi.

Some properties of the trace operator includes:

  1. tr(A)=tr(A).
  2. tr(A+B)=tr(A)+tr(B).
  3. tr(aA)=atr(A) for aR.
  4. tr(An)=i=1nλin where λi is the i-th eigenvalue of A.
  5. tr(A1)=i=1n1λi.