Mathematics of Information Teaching Group Publications Home

Matrices and fundamental spaces

Matrices, the basics

What is a Matrix?

A matrix is a finite, ordered sequence of numbers arranged in a rectangle with a number of rows and columns.

Examples:

\[A = \begin{pmatrix} 3 & -1 \\ 1 & 2 \\ \end{pmatrix},\qquad B = \begin{pmatrix} -1 & 1 \\ 7 & 4 \\ 0 & 3 \\ \end{pmatrix}.\]

To refer the element in row $i$ and column $j$ of $A$, we write $A_{ij}$. For example, above, $A_{12}=-1.$

The dimension of a matrix is written as $m\times n$, where $m$ is the number of rows and $n$ is the number of columns. We write $A_{m\times n}$ to denote a matrix of dimension $m\times n$.

Addition: Matrices can be added and multiplied together. The addition of two matrices with the same dimensions is obtained by adding the elements in the same positions, as shown below. Multiplication is discussed later in detail.

\[\begin{pmatrix}1&2&3\\4&5&6\end{pmatrix} + \begin{pmatrix}7&8&9\\10&11&12\end{pmatrix} = \begin{pmatrix}8&10&12\\14&16&18\end{pmatrix}.\]


Transposition: We can transpose a matrix by mirroring it with respect to the diagonal:

\[\begin{pmatrix} 2 & -3 \\ -1 & 4 \\ 1 & 0 \\ \end{pmatrix}^{T} = \begin{pmatrix} 2 & -1 & 1 \\ -3 & 4 & 0 \\ \end{pmatrix}\]


Vectors as matrices: Vectors are special cases of matrices, where either one row or one column:

We use the notation $v = \left( v_{1},v_{2},\ldots,v_{n} \right)$ for both row and column vectors. If we want to be precise, to write a column vector as a row vector, we can write $v^T=\left( v_{1},v_{2},\ldots,v_{n} \right)$. If $v$ is a column vector, $v^T$ is a row vector and vice versa.

It is usually helpful to think of a matrix as a collection of (usually column) vectors.

\[\begin{pmatrix} \color{blue}{ - 1} & \color{blue}{1} \\ \color{brown}{0} & \color{brown}{3} \\ \color{green}{2 }& \color{green}{- 2} \\ \end{pmatrix},\qquad \begin{pmatrix} \color{blue}{ -5 }& \color{brown}{-6} & \color{green}{-4 }\\ \color{blue}{5 }& \color{brown}{8 }& \color{green}{7} \\ \color{blue}{ -1 }& \color{brown}{0} & \color{green}{1 }\\ \end{pmatrix}.\]

Matrix-vector multiplication

We can multiply a vector $x$ and a matrix $A$ in two different ways: \(Ax\) and \(xA\)

\[\begin{pmatrix} \color{blue}{1} & \color{brown}{-1} \\ \color{blue}{3} & \color{brown}{-4} \\ \color{blue}{-1} & \color{brown}{2} \\ \end{pmatrix} \begin{pmatrix} \color{blue}{2} \\ \color{brown}{1} \\ \end{pmatrix} = \color{blue}{2} \begin{pmatrix} \color{blue}{1} \\ \color{blue}{3} \\ \color{blue}{-1}\\ \end{pmatrix} + \color{brown}{1} \begin{pmatrix} \color{brown}{-1} \\ \color{brown}{-4} \\ \color{brown}{2} \\ \end{pmatrix} = \begin{pmatrix} 1 \\ 2 \\ 0 \\ \end{pmatrix}\]

More generally, for \(A = \begin{pmatrix} \color{blue}{a_{11}} & a_{12} & a_{13} \\ \color{blue}{a_{21}} & a_{22} & a_{23} \\ \color{blue}{a_{31}} & a_{32} & a_{33} \\ \color{blue}{a_{41}} & a_{42} & a_{43} \\ \end{pmatrix},x = \begin{pmatrix} \color{blue}{x_{1}} \\ x_{2} \\ x_{3} \\ \end{pmatrix},\) we have

\[Ax = \color{blue}{x_{1}}\begin{pmatrix} \color{blue}{a_{11}} \\ \color{blue}{a_{21}} \\ \color{blue}{a_{31}} \\ \color{blue}{a_{41}} \\ \end{pmatrix} + x_{2}\begin{pmatrix} a_{12} \\ a_{22} \\ a_{32} \\ a_{42} \\ \end{pmatrix} + x_{3}\begin{pmatrix} a_{13} \\ a_{23} \\ a_{33} \\ a_{43} \\ \end{pmatrix}= \begin{pmatrix} \color{blue}{x_{1}a_{11}} + x_{2}a_{12} + x_{3}a_{13} \\ \color{blue}{x_{1}a_{21}} + x_{2}a_{22} + x_{3}a_{23} \\ \color{blue}{x_{1}a_{31}} + x_{2}a_{32} + x_{3}a_{33} \\ \color{blue}{x_{1}a_{41}} + x_{2}a_{42} + x_{3}a_{43} \\ \end{pmatrix}\] \[\begin{pmatrix} \color{blue}{ - 1} & \color{brown}{1 }& \color{green}{0} \\ \end{pmatrix}\begin{pmatrix} \color{blue}{ - 1} & \color{blue}{1} \\ \color{brown}{0} & \color{brown}{3} \\ \color{green}{2 }& \color{green}{- 2} \\ \end{pmatrix} = \color{blue}{ - 1} \begin{pmatrix} \color{blue}{ - 1} & \color{blue}{1} \\ \end{pmatrix} + \color{brown}{1 } \begin{pmatrix} \color{brown}{0} & \color{brown}{3} \\ \end{pmatrix} + \color{green}{0} \begin{pmatrix} \color{green}{2 }& \color{green}{- 2} \\ \end{pmatrix} = \begin{pmatrix} 1 & 2 \\ \end{pmatrix}\]

We can multiply a column vector $v$ by a matrix from the left by first writing it as row vector, i.e., $v^T A$.

We can view matrix-vector multiplication (also vector-matrix multiplication) as a transformation, that is a function that maps vectors to vectors. The input to the transformation is $x$ and the output is $Ax$ (or $xA$). For example, a transformation may rotate each vector by 90 degrees.



Let $$A = \begin{pmatrix}0 & 1 \\ -1 & 0\end{pmatrix}.$$ Find $Ax$ and $Ay$, where $$x = \begin{pmatrix}1\\2\end{pmatrix},\qquad y = \begin{pmatrix}4\\3\end{pmatrix}.$$ Show $x,y,Ax,Ay$ on Cartesian axes. Viewed as a transformation, what does this matrix do?


Matrix-vector multiplication $Ax$ is a linear transformation:

Note: this also holds for the vector-matrix multiplication $xA$.

Matrix multiplication

We can also multiply two matrices together. In this case, the $i$-th column of the result is obtained by multiplying the $i$-th column of the second matrix by the first matrix. For example,

\[\begin{pmatrix} 2 & -3 \\ -1 & 4 \\ 1 & 0 \\ \end{pmatrix}\begin{pmatrix} \color{blue}{ -1 }&\color{brown}{ 0 }&\color{green}{ 1 }\\ \color{blue}{1 }&\color{brown}{ 2 }& \color{green}{2 }\\ \end{pmatrix} = \begin{pmatrix} \color{blue}{ -5 }& \color{brown}{-6} & \color{green}{-4 }\\ \color{blue}{5 }& \color{brown}{8 }& \color{green}{7} \\ \color{blue}{ -1 }& \color{brown}{0} & \color{green}{1 }\\ \end{pmatrix}\]

Note for example that the first column of the result is obtained by multiplying the first column of the second matrix by the first matrix:

\[\begin{pmatrix} 2 & -3 \\ -1 & 4 \\ 1 & 0 \\ \end{pmatrix}\begin{pmatrix} -1\\ 1\\ \end{pmatrix} = (-1)\begin{pmatrix} 2 \\ -1 \\ 1 \\ \end{pmatrix}+ (1) \begin{pmatrix} -3 \\ 4 \\ 0 \\ \end{pmatrix}= \begin{pmatrix} -5\\ 5\\ -1\\ \end{pmatrix}\]

We can also view matrix multiplication as follows: If $C=AB$, then $C_{ij}$ is the result of the inner product of the $i$-th row of $A$ and the $j$-th column of $B$. The number of columns of $A$ must equal the number of rows of $B$. $A_{n\times m} B_{m \times p} = C_{n \times p}$.

Find $$\begin{pmatrix} -1 & 1 \\ 2 & 2 \\ \end{pmatrix}\begin{pmatrix} -2 & 3 & 0 \\ 2 & 0 & 1 \\ \end{pmatrix}. $$


Note that matrix-vector multiplication can be viewed as a special case of matrix multiplication.

Properties of matrix multiplication

Recall that $A = \begin{pmatrix}0 & 1 \\ -1 & 0\end{pmatrix}$ rotates any vector by 90 degrees.


The identity matrix

The $n \times n$ identity matrix has 1s on the diagonal and 0s elsewhere \(I_{n} = \begin{pmatrix} 1 & \ldots & 0 \\ \vdots & \ddots & \vdots \\ 0 & \ldots & 1 \\ \end{pmatrix}\)

Find the result: $A_{m \times n}I_{n}$ = $,\quad I_{m}A_{m \times n}$ = $,\quad x^{T}I$ = $,\quad Ix$ = \(\qquad\)

The four fundamental spaces of a matrix

There are four subspaces associated with each matrix. The column space, the row space, the null space, and the left null space. The column space and the null space are particularly important in error correction.

The row space

The row space of $A$ is the span of the rows of $A$

To represent the row space in a simple way, we can find a basis for it. We can do so as explained in the last section, where we discussed how to find a basis for a subspace. When we apply this method to rows of a matrix, adding the multiple of a row to the other is called an elementary row operation and if we find the basis in the reduced form, this form is called the reduced row-echelon form. We can then represent the row space as a set of vectors with free and dependent coordinates.

The row rank of a matrix is the dimension of its row space.

Find a basis for the row space of $$B = \begin{pmatrix} 1 & 1 & 3 \\ 1 & 3 & 2 \\ 2 & 4 & 5 \\ \end{pmatrix}.$$ Write the row space as a set of vectors with free and dependent coordinates. What is the row rank of the matrix.


The column space

The column space of $A$ is the span of the columns of $A$

Finding a basis for the column space is similar to row space, except that here we manipulate the columns. As an example, let us find a basis for the column space of \(A = \begin{pmatrix} 1 & 1 & 3 \\ 1 & 3 & 2 \\ 2 & 4 & 6 \\ \end{pmatrix}\)

\[A \rightarrow \begin{pmatrix} 1 & 0 & 0 \\ 1 & 2 & -1 \\ 2 & 2 & 0 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 0 & 0 \\ 1 & 1 & -1 \\ 2 & 1 & 0 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 1 & 1 & 1 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{pmatrix} \rightarrow \left\{\begin{pmatrix} a \\ b \\ c \\ \end{pmatrix} \vert a, b, c \in \mathbb{R} \right\}.\]

For example, in the first step, we have subtracted the first column from the second column and 3 times the first column from the third column. In the second step, we scaled the second column and then subtracted scaled versions of it from the other columns and so on. These are called elementary column operations.

The dimension of the column space is called the column rank.

Find a reduced basis for the column space of $$A = \begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & 2 & 3 & 4 \\ 4 & 9 & 14 & 19 \\ \end{pmatrix}$$ and find the column rank.


Find a basis for the column space of $B = \begin{pmatrix} 1 & 1 & 3 \\ 1 & 3 & 2 \\ 2 & 4 & 5 \\ \end{pmatrix}.$ Find the column space as a set of vectors with free and dependent coordinates and find its dimension.

Rank of a matrix

What is the relationship between row and column ranks? They are equal, as we saw above for

\[B = \begin{pmatrix} 1 & 1 & 3 \\ 1 & 3 & 2 \\ 2 & 4 & 5 \\ \end{pmatrix}.\]

As another example, recall that the column rank of the matrix $A$ given below is 2. Let’s find its row rank

\[A = \begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & 2 & 3 & 4 \\ 4 & 9 & 14 & 19 \\ \end{pmatrix}\] \[\begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & 2 & 3 & 4 \\ 4 & 9 & 14 & 19 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 1 & 1 & 1 \\ 0 & 1 & 2 & 3 \\ 0 & 5 & 10 & 15 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 0 & -1 & -2 \\ 0 & 1 & 2 & 3 \\ 0 & 0 & 0 & 0 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 0 & -1 & -2 \\ 0 & 1 & 2 & 3 \\ \end{pmatrix}.\]

and so the row rank of $A$ is also 2.

The row rank is equal to the column rank and is called the rank of the matrix.

The null space

Let $A$ be an $m\times n$ matrix. The null space of $A$, denoted $NS(A)$, is the set of $n$-dimensional vectors $x$ satisfying $Ax=\mathbf 0$.

Note that elementary row operations are like adding one equation to another one and so they don’t change the set of vectors satisfying $Ax=\mathbf 0$. So to find the null space, we first write the matrix in the reduced row echelon form.

Example: the null space of

\[A = \begin{pmatrix} 1 & - 1 & 2 & 1 \\ -1 & 2 & 1 & 2 \\ 2 & 1 & 2 & - 2 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & - 1 & 2 & 1 \\ 0 & 1 & 3 & 3 \\ 0 & 3 & -2 & -4 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 0 & 5 & 4 \\ 0 & 1 & 3 & 3 \\ 0 & 0 & -11 & -13 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 0 & 0 & - 21/11 \\ 0 & 1 & 0 & - 6/11 \\ 0 & 0 & 1 & 13/11 \\ \end{pmatrix}\]

So the null space of $A$ is the set of solutions to

\[\begin{pmatrix} 1 & 0 & 0 & - 21/11 \\ 0 & 1 & 0 & - 6/11 \\ 0 & 0 & 1 & 13/11 \\ \end{pmatrix} \begin{pmatrix}x_1\\ x_2\\ x_3\\ x_4\end{pmatrix}=\begin{pmatrix}0\\0\\0\\0\end{pmatrix},\]

which we can write as

\[\begin{matrix} x_{1} - \frac{21}{11}x_{4} = 0 \\ x_{2} - \frac{6}{11}x_{4} = 0 \\ x_{3} + \frac{13}{11}x_{4} = 0 \\ \end{matrix}\]

This allows us to express $x_1, x_2, x_3$ in terms of $x_4$, then write out the null space vector as:

\[NS(A) = \left\{ \begin{pmatrix} \frac{21}{11}x_{4} \\ \frac{6}{11}x_{4} \\ -\frac{13}{11}x_{4} \\ x_{4} \\ \end{pmatrix} \vert x_4 \in \mathbb{R} \right\}\]

On the other hand, the row space of $A$ is given by

\[RS(A) = \left\{ \begin{pmatrix} x_1 \\ x_2\\ x_3\\ \frac{-21x_1-6x_2+13x_3}{11}\\ \end{pmatrix} \vert x_1,x_2,x_3 \in \mathbb{R} \right\}.\]

We can see the set of free and dependent coordinates complement each other in the row space and the null space. This shows the following fact:

For a matrix with $n$ columns, the row rank plus the dimension of the null space is equal to $n$.


Find the null space and the row space of the matrix $$A = \begin{pmatrix} -1 & 1 & 0 & 1 \\ 3 & 1 & -2 & -1 \\ 4 & -2 & -1 & -3 \\ \end{pmatrix}$$


The generator matrix

Note that in the previous example, we can write the null space of the matrix $A$ as a linear combination:

\[\begin{pmatrix} (x_{3} + x_{4})/2 \\ (x_{3} - x_{4})/2 \\ x_{3} \\ x_{4} \\ \end{pmatrix} = \begin{pmatrix} 1/2 \\ 1/2 \\ 1 \\ 0 \\ \end{pmatrix}x_{3} + \begin{pmatrix} 1/2 \\ -1/2 \\ 0 \\ 1 \\ \end{pmatrix}x_{4}\]

The null space of $A$ is the column space of the matrix

\[G = \begin{pmatrix} \begin{matrix} 1/2 \\ 1/2 \\ 1 \\ 0 \\ \end{matrix} & \begin{matrix} 1/2 \\ -1/2 \\ 0 \\ 1 \\ \end{matrix} \\ \end{pmatrix}\]

We call this the generator of the null space. That is, the null space is the set of vectors of the form \(G\begin{pmatrix} x_{1} \\ x_{2} \\ \end{pmatrix}.\)

This generator matrix is not unique. For example, we can start the row operations from the opposite side (bottom right) of the matrix:

\[\begin{pmatrix} -1 & 1 & 0 & 1 \\ 3 & 1 & -2 & -1 \\ 4 & -2 & -1 & -3 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1/3 & 1/3 & -1/3 & 0 \\ 5/3 & 5/3 & -5/3 & 0 \\ 4 & -2 & -1 & -3 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 0 & 0 & 0 & 0 \\ 5/3 & 5/3 & -5/3 & 0 \\ 4 & -2 & -1 & -3 \\ \end{pmatrix} \rightarrow \\ \begin{pmatrix} 1 & 1 & -1 & 0 \\ -4/3 & 2/3 & 1/3 & 1 \\ \end{pmatrix} \rightarrow \begin{pmatrix} -1 & -1 & 1 & 0 \\ -1 & 1 & 0 & 1 \\ \end{pmatrix}\] \[\rightarrow \begin{cases} x_3 = x_1 + x_2 \\ x_4 = x_1 - x_2 \end{cases}\] \[\begin{pmatrix} x_{1} \\ x_{2} \\ x_{1} + x_{2} \\ x_{1} - x_{2} \\ \end{pmatrix} = \begin{pmatrix} 1 \\ 0 \\ 1 \\ 1 \\ \end{pmatrix} x_{1} + \begin{pmatrix} 0 \\ 1 \\ 1 \\ -1 \\ \end{pmatrix} x_{2} \rightarrow G = \begin{pmatrix} 1 & 0 \\ 0 & 1 \\ 1 & 1 \\ 1 & -1 \\ \end{pmatrix},NS = \left\{ G\begin{pmatrix} x_{1} \\ x_{2} \\ \end{pmatrix}:x_{1},x_{2} \in {\mathbb{R}} \right\}\]
What are the row and null spaces of $$A = \begin{pmatrix} 0 & 0 & 1 \\ 0 & 0 & 2 \\ \end{pmatrix}$$ Find a generator for the null space.


What are the row and null spaces and a generator matrix of $$A = \begin{pmatrix} 1 & 1 & 2 \\ 2 & 1 & 4 \\ \end{pmatrix}$$


The column space and left null space

The left null space (LNS) of $A$: the set of vectors $x$ such that $x^TA = 0$

For an $m \times n$ matrix $A$, the CS and LNS contain $m$-dimensional vectors

What is the relationship between CS and LNS of $A$? $dim(CS) + dim(LNS) = m$, where dim stands for dimension.

The left null space is not useful for us in the future, so it will not be discussed in detail.

In summary

Suppose we have a matrix A with M rows and N columns. Then, we can define four vector spaces:

It turns out these spaces tell us a lot about the underlying linear operation performed by A. To understand why, we need to introduce a couple more definitions about vectors.

The fundamental theorem of linear algebra

Theorem: For an $m \times n$ matrix $A$: