Linear algebra and notations

This section introduces the basic concepts of linear algebra and notations used in this course. The concepts are introduced in a self-contained manner, and you can skip this section if you are already familiar with the concepts.

Scalars, vectors, and matrices

  • Scalars: a scalar is a single number. In this course, if not specified, scalars are denoted by lowercase letters, e.g. x=3.14. When introducing a scalar, we will specify its type, e.g. xR, where R is the set of real numbers.

  • Vectors: a vector is an array of numbers, which are arranged in order. Usually we denote vectors as lowercase letters in bold, e.g.

    x=[x1,x2,,xn],

    where the superscript denotes a common vector/matrix operation called transpose, which flips the row and column, e.g. [x1x2]=[x1,x2], and [x1,x2]=[x1x2]. The elements of a vector can be accessed by their index, and denoted as a scalar with a subscript, e.g. x1 is the first element of x. We can also index a set of elements of a vector. For example, we can define the set S={2,4} and then access the 2nd and 4th elements of x by S, i.e. xS=[x2,x4]. We can also index a set of elements of a vector by a boolean array, e.g. xb=[x1,x3], where b=[True,False,True,,False]. When introducing a vector, we can specify its type, e.g. if each element in x is in R, we can specify it as xRn, where Rn is the set of n-dimensional real vectors.

  • Matrices: a matrix is a 2D array of numbers. Typically we denote matrices as uppercase letters in bold, e.g.

    X=[x1,1x1,2,x1,3x2,1x2,2x2,3].

    If a real valued matrix X has m rows and n columns, we can specify it as XRm×n. We usually identify an element of a matrix as a scalar with its row and column indices, e.g. x2,3 is the element in the 2nd row and 3rd column of X. We can also access an entire row of a matrix by writing “:” for the coordinate of columns, e.g. x2,: is the 2nd row of X. We can also access columns of a matrix in the same way, e.g., x:,3 is the 3rd column of X. The transpose of a matrix flips the rows and columns along the diagonal, e.g.

    [1234]=[1324].

Operations on matrices

  • A matrix X can be multiplied by a scalar α or add a scalar to a matrix:

    (αX)i,j=αxi,j, and (X+α)i,j=xi,j+α.
  • Addition and subtraction: we can add or subtract two matrices with the same shape. The result is that all corresponding entries are added, i.e.

    (X+Y)i,j=xi,j+yi,j.
  • Matrix multiplication: If the number of columns of matrix X is equal to the number of rows of matrix Y, the matrices can be multiplied in the order X, Y. The result will be a new matrix XY, that has the same number of rows as X and the same number of columns as Y. The entries (XY)i,j will be the following combination of the entries of row i of X and column j of Y, i.e.

    (XY)i,j=k=1nxi,kyk,j.
  • Element-wise multiplication: we can also multiply two matrices with the same shape element-wise, i.e.

    (XY)i,j=xi,jyi,j,

    where is the symbol for element-wise multiplication, and XY is also called the Hadamard product of X and Y.

Examples

  • The multiplication of a number and a matrix

    2[1234]=[2×12×22×32×4]=[2468].
  • The sum of two matrices of the same shape

    [1234]+[5678]=[1+52+63+74+8]=[681012].
  • The multiplication of two matrices:

    [1234][5678910]=[1×5+2×81×6+2×91×7+2×103×5+4×83×6+4×93×7+4×10]=[212427475461].

Some properties of matrix multiplication:

  • (X)=X.

  • (XY)=YX.

  • (X+Y)=X+Y.

  • XI=IX=X, where I is the identity matrix.

  • XY=YX if X and Y are square matrices.

  • (αX)Y=α(XY).

  • X(YZ)=(XY)Z.

  • X(Y+Z)=XY+XZ.

Special matrices

  • Diagonal matrices contain non-zero elements only on the diagonal, i.e. xi,j=0 for ij. For example, the following matrix is a diagonal matrix:

    [100020003].

    All diagonal matrices are square.

  • Identity matrices are special diagonal matrices with ones on the diagonal (and zeros elsewhere), i.e. xi,j=1 for i=j and xi,j=0 for ij. For example, the following matrix is an identity matrix:

    [100010001].
  • Symmetric matrices are square matrices that are equal to their transpose, i.e. X=X, or Xi,j=Xj,i. For example, the following matrix is a symmetric matrix:

    [123245356].
  • Invertible matrices are square matrices that can be multiplied with another matrix to yield the identity matrix. The inverse matrix of a matrix X is denoted as X1, and according to the definition XX1=X1X=I. The inverse matrix of an identity matrix is itself, e.g.

    [100010001]1=[100010001].
  • An Orthogonal matrix is a square matrix whose columns are mutually orthogonal and have unit length, i.e. XX=XX=I, where I is the identity matrix.

Exercises

1. [12000800023]

What kind of matrices is it? There can be multiple answers.

    a. Diagonal

    b. Identity

    c. Symmetric

    d. Invertible

    e. Orthogonal

Compare your answer with the solution below

Click to show

a , c, d.

The given matrix has values only in the diagonal; that’s why it’s a diagonal matrix. The diagonal values are not 1, so it’s not an identity matrix. If you transpose the given matrix, it will equal the given matrix, so it’s symmetric. A diagonal matrix without any zero on its diagonal is always invertible, so this is an invertible matrix. For the orthogonal matrix XXT=I, which is not valid for our given matrix, so it’s not an orthogonal matrix.

2. A = [85971914]; B = [61315172212039]

Calculate the following matrix operations by hand.

i. AB= ?

ii. 2A = ?

iii. AB+2A = ?

Compare your answer with the reference solution below

Click to show

i. [133241261365551459]

ii. [161018143828]

iii. [149251279379589487]