Introduction to matrices

Linear mathematics
Matrices
Author

Jessica Taberner

Summary
Matrices are rectangular arrays of mathematical objects with entries arranged in rows and columns. Matrices are a very useful concept within mathematics, you’ll see them used for solving simultaneous equations and much more. This guide will explain what they are, some special kinds of matrices, and how to add, subtract, and scalar multiply matrices.
Narration of study guide:  

What is a matrix?

A matrix is a rectangular array or table, with entries in rows and columns. Understanding matrices can make solving equations more efficient and can open the door to learning much more mathematics.

If you have read Guide: Introduction to solving simultaneous equations then one way of thinking of matrices is as an array encoding the coefficients of the variables of your simultaneous equations.

Matrices are a fundamental tool within mathematics, and they have a wide range of real-life applications. They are used in computer graphics, data analysis, search engine optimization, cryptography, economics, robotics, genetics, quantum mechanics, and many more areas of study. Matrices are used anywhere where information needs to be analyzed and calculated efficiently.

In this guide, you will see how you can: read, write, and understand matrices; learn how to do addition, subtraction and scalar multiplication with matrices; and be able to identify some special matrices.

Working with matrices

NoteDefinition of a matrix

A \(m \times n\) matrix \(A\) is a rectangular array of \(mn\) many numbers (called entries) set out in \(m\) rows and \(n\) columns. You can write it like so:

\[ A = \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{bmatrix} \]

This matrix has dimension \(m \times n\).

The notation \(a_{ij}\) refers to the \((i,j)\)th entry of your matrix, that is the number in the \(i\)th row and the \(j\)th column. An alternative way of writing the above matrix is \(A = [a_{ij}]\).

You can specify the \((i,j)\)th entry \(a_{ij}\) of a particular matrix \(A\) by writing \([A]_{ij} = a_{ij}\).

Tip

The entries in a matrix are usually numbers, but they can be other mathematical objects. Any type of number could be an entry in a matrix, positive or negative, rational or irrational, real or complex. (If complex numbers are unfamiliar to you, you can read more about them at Guide: Introduction to complex numbers.

Note that while entries can be other mathematical objects, for this study guide you will exclusively use entries within the real numbers.

NoteExample 1

Here are some matrices:

\[ A =\begin{bmatrix} 0 & -2 \\ \pi & 5 \\ 1/3 & 0 \end{bmatrix},\quad\textsf{and}\quad B = \begin{bmatrix} -1 & 2/5 & 0 & \sqrt{3} \end{bmatrix} \]

As \(A\) has three rows and two columns, it has dimension \(3 \times 2\). The entry in the 2nd row and 1st column is called \(a_{21} = [A]_{21}\), and here that is equal to \(\pi\). The entry in the 1st row and 2nd column is called \(a_{12} = [A]_{21}\), and here that is equal to \(-2\). You can notice here that \(a_{21}\) is not equal to \(a_{12}\).

Matrix \(B\) here has dimension \(1 \times 4\), as it has one row and four columns. The entry in the 1st row and 2nd column is called \(b_{12} = [B]_{12}\), and here that is equal to \(2/5\). The entry in the 1st row and 4th column is called \(b_{14} = [B]_{12}\), and here that is equal to \(\sqrt{3}\).

\[ C =\begin{bmatrix} \sqrt{2} \\ 11 \\ -3/8 \end{bmatrix}, \quad\textsf{ and }\quad D= \begin{bmatrix} -5 & 1/2 & 0 \\ 0 & 7 & 4/9 \\ -\pi & 0 & -\sqrt{3} \\ -1 & 5 & 0 \\ 1/4 & 0 & 8 \end{bmatrix} \]

Matrix \(C\) has dimension \(3 \times 1\), as it has three rows and one column.

As \(D\) has five rows and three columns, the matrix \(D\) has dimension \(5 \times 3\).

You can notice that \(B\) only has one row; you can call such a matrix a row matrix. Similarly, you would call a matrix like \(C\), with only one column, a column matrix. These are commonly known as vectors. You can read more about vectors in Guide: Introduction to vectors.

One important set of entries in a matrix is the main diagonal:

NoteDefinition of a main diagonal

For a \(m\times n\) matrix \(A=[a_{ij}]\), the entries \({a_{11},a_{22},\ldots,a_{kk}}\) make up the main diagonal of \(A\). This is where

  • \(k = m\) if \(m < n\)
  • \(k = n\) if \(n\leq m\).

You can write the main diagonal using this notation:

\[\textsf{diag}(A) = ({a_{11},a_{22},\ldots,a_{kk}})\]

which state the entries of the main diagonal.

Warning

\(\textsf{diag}(A) = ({a_{11},a_{22},\ldots,a_{nn}})\) is not a matrix, but a set of entries of the matrix.

NoteExample 3

What are the main diagonals of the matrices in Example 1?

Since \(A\) is a \(3\times 2\) matrix, it follows that \(n < m\) and so \(k = 2\), meaning the main diagonal of \(A\) is \(\textsf{diag}(A) = (a_{11},a_{22}) = (0,5)\). You can see these entries highlighted in bold below:

\[A =\begin{bmatrix}\mathbf{0} & -2 \\\pi & \mathbf{5} \\1/3 & 0 \end{bmatrix}\]

Since \(B\) is a \(1\times 4\) matrix, it follows that \(m < n\) and so \(k = 1\), meaning the main diagonal of \(B\) is \(\textsf{diag}(B) = (b_{11}) = (-1)\). You can see this entry highlighted in bold below: \[B = \begin{bmatrix}\mathbf{-1} & 2/5 & 0 & \sqrt{3} \end{bmatrix}\]

You do not need to be so thorough every time. You can read off the main diagonals of \(C\) and \(D\) (entries highlighted in bold):

\[ C =\begin{bmatrix} \mathbf{\sqrt{2}} \\ 11 \\ -3/8 \end{bmatrix} \quad\textsf{ and }\quad D= \begin{bmatrix} \mathbf{-5} & 1/2 & 0 \\ 0 & \mathbf{7} & 4/9 \\ \pi & 0 & \mathbf{-\sqrt{3}} \\ -1 & 5 & 0 \\ 1/4 & 0 & 8 \end{bmatrix} \]

to say \[\textsf{diag}(C) = (\sqrt{2})\quad\textsf{and}\quad\textsf{diag}(D) = (-5,7,-\sqrt{3}).\]

Special matrices

There are special matrices that often appear in mathematics and statistics.

Zero matrix

There are a special class of matrices where all of the entries are zero; they are somewhat uninspiringly called the zero matrices.

NoteDefinition of a zero matrix

The \(m\times n\) zero matrix \(0_{m\times n}\) is the \(m\times n\) matrix where all entries are \(0\).

NoteExample 3

Here are some zero matrices: \[0_{1\times 3} = \begin{bmatrix}0&0&0\end{bmatrix},\quad 0_{3\times 1} = \begin{bmatrix}0\\0\\0\end{bmatrix}, \quad 0_{4\times 3} = \begin{bmatrix}0&0&0\\0&0&0\\0&0&0\\0&0&0\end{bmatrix}\]

There is one zero matrix for every ordered pair of positive numbers \((m,n)\). There is one warning to say though:

Warning

If \(m\neq n\), then \(0_{m\times n} \neq 0_{n\times m}\), as the matrices have different shapes! You saw this in Example 3, where \(0_{1\times 3} \neq 0_{3\times 1}\).

Finally, here’s a way to define zero matrices using the alternative definition of a matrix.

Tip

You can use the alternate way of writing a matrix to define the zero matrix: \[0_{m\times n} = [a_{ij}] \quad \textsf{ where }\quad a_{ij} = 0 \textsf{ for }1\leq i \leq m\textsf{ and }1\leq j \leq n.\] This way of defining matrices is incredibly common in computer coding, as it relies on for loops.

Square matrix

The only time \(0_{m\times n} = 0_{n\times m}\) is if \(m = n\). Then, the number of rows equals the number of columns, and so the matrix is square. This is precisely the definition of a square matrix:

NoteDefinition of a square matrix

A matrix \(A\) is a square matrix if the number of rows of \(A\) equals the number of columns of \(A\). So an \(m\times n\) matrix is square if \(m = n\).

NoteExample 4

Here are some square matrices: \[E = \begin{bmatrix}0&-4&\pi&6\\e&-1&1&1\\6&6&6&6\\9&4&3&-2\end{bmatrix},\quad F = \begin{bmatrix}1&1\\0&1\end{bmatrix}, \quad 0_{3\times 3} = \begin{bmatrix}0&0&0\\0&0&0\\0&0&0\end{bmatrix}\]

Upper and lower triangular matrices

A special kind of square matrix are upper and lower triangular matrices, where a large portion of the entries are \(0\).

NoteDefinition of upper and lower triangular matrices

Suppose that \(A,B\) are \(n\times n\) square matrices. A matrix \(A\) is an upper triangular matrix if every entry below the main diagonal of \(A\) is \(0\). Similarly, \(B\) is a lower triangular matrix if every entry above the main diagonal of \(B\) is \(0\).

NoteExample 4

None of the matrices in Example 1 are upper or lower triangular, as they are all not square. The matrix \(E\) in Example 2 is not upper triangular, as there is only one entry equalling \(0\) and it is on the main diagonal.

The matrix \(F\) in Example 2 is upper triangular, as all the entries below the main diagonal are \(0\). You can see this in the recreation of \(F\) below, where the main diagonal is highlighted in bold:

\[F = \begin{bmatrix}\mathbf{1}&1\\0&\mathbf{1}\end{bmatrix}\]

The zero matrix \(0_{3\times 3}\) is both upper and lower triangular; as the entries both above and below the main diagonal are \(0\). The main diagonal is highlighted in bold to help you visualise this: \[\quad 0_{3\times 3} = \begin{bmatrix}\mathbf{0}&0&0\\0&\mathbf{0}&0\\0&0&\mathbf{0}\end{bmatrix}\]

Tip

Similar to the zero matrices, you can use alternative definitions to specify upper and lower triangular matrices in more detail. For instance, for an \(n\times n\) upper triangular matrix \(A\): \[A = [a_{ij}] \quad \textsf{ where }\quad a_{ij} = 0 \textsf{ for }1\leq i < j\leq n\] and an \(n\times n\) lower triangular matrix \(B\) can be defined by \[B = [b_{ij}] \quad \textsf{ where }\quad a_{ij} = 0 \textsf{ for }1\leq j < i\leq n.\]

Diagonal matrices

NoteDefinition of a diagonal matrix

Let \(D\) be a square \(n\times n\) matrix. Then \(D\) is a diagonal matrix if all entries not on the main diagonal are \(0\).

This means that diagonal matrices are both upper and lower triangular matrices. So if a matrix is not upper triangular, then it can’t possibly be a diagonal matrix.

NoteExample 5

The matrix \(F\) in Example 2 is not diagonal. Although it is upper triangular, as all the entries below the main diagonal are \(0\), it is not diagonal as there is a non-zero entry \(1\) above the main diagonal.

\[F = \begin{bmatrix}\mathbf{1}&1\\0&\mathbf{1}\end{bmatrix}\]

The following matrices are all diagonal, with the main diagonal highlighted in bold so you can see that the entries above and below are all \(0\);

\[G = \begin{bmatrix}\mathbf{0}&0&0\\0&\mathbf{-1}&0\\0&0&\mathbf{-1}\end{bmatrix}, \quad H = \begin{bmatrix}\mathbf{76}&0\\0&\mathbf{-45}\end{bmatrix}, \quad I_4 = \begin{bmatrix}\mathbf{1}&0&0&0\\0&\mathbf{1}&0&0\\0&0&\mathbf{1}&0\\0&0&0&\mathbf{1}\end{bmatrix}\]

The zero matrix \(0_{3\times 3}\) is diagonal, as the entries both above and below the main diagonal are \(0\): \[0_{3\times 3} = \begin{bmatrix}\mathbf{0}&0&0\\0&\mathbf{0}&0\\0&0&\mathbf{0}\end{bmatrix}\]

Tip

You can define an \(n\times n\) diagonal matrix \(A\) using the following: \[A = [a_{ij}] \quad \textsf{ where }\quad a_{ij} = 0 \textsf{ for }1\leq i \neq j\leq n.\]

Identity matrices

The final special kind of matrix is the idea of an identity matrix:

NoteDefinition of the identity matrix \(I_n\)

The \(n\times n\) square matrix with all entries \(1\) on the main diagonal and \(0\)’s everywhere else is called the \(n\times n\) identity matrix \(I_n\).

You saw an example of an identity matrix in Example 5 (\(I_4\)). Here are two more examples \[I_2 = \begin{bmatrix}1&0\\0&1\end{bmatrix}, \quad I_6 = \begin{bmatrix}1&0&0&0&0&0\\0&1&0&0&0&0\\0&0&1&0&0&0\\0&0&0&1&0&0\\0&0&0&0&1&0\\0&0&0&0&0&1\end{bmatrix}\]

Tip

The reason why identity matrices are called the identity matrices is because they act as ‘multiplicative identities’. See Guide: Matrix multiplication for more.

You can define an \(n\times n\) identity matrix \(I_n\) using the following: \[I_n = [a_{ij}] \quad \textsf{ where }\quad a_{ij} = \begin{cases}1 \textsf{ for }1\leq i = j\leq n\\[0.5em] 0 \textsf{ for }1\leq i \neq j\leq n.\end{cases}\]

Addition and subtraction with matrices

In this section, you will see when and how you can add and subtract matrices. The first thing to notice is the following.

Important

You can only add and subtract matrices if they share the same dimensions.

NoteDefinition of matrix addition and subtraction

Let \(A\) and \(B\) be \(m\times n\) matrices (so they have the same dimension). The matrix sum of \(A\) and \(B\) can be calculated by adding corresponding entries of \(A\) and \(B\),

\[(A + B)_{ij} = a_{ij} + b_{ij}\]

Similarly, the matrix difference of \(A\) and \(B\) can be calculated by subtracting corresponding entries of \(A\) and \(B\),

\[(A - B)_{ij} = a_{ij} - b_{ij}\]

NoteExample 4

Let \(A\) and \(B\) be the following two \(2 \times 2\) matrices.

\[A =\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \quad\textsf{ and }\quad B = \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix}\]

The sum \(A + B\) is:

\[A + B = \begin{bmatrix} 1+5 & 2+6 \\ 3+7 & 4+8 \end{bmatrix}= \begin{bmatrix} 6 & 8 \\ 10 & 12 \end{bmatrix}\] The difference \(A-B\) is:

\[A - B = \begin{bmatrix} 1-5 & 2-6 \\ 3-7 & 4-8 \end{bmatrix}= \begin{bmatrix} -4 & -4 \\ -4 & -4 \end{bmatrix}\]

NoteExample 5

Now let \(A\) and \(B\) be two \(3 \times 4\) matrices.

\[A = \begin{bmatrix} 1 & -3 & 5 & -4 \\ 3 & 0 & -2 & 2 \\ -7 & 8 & 4 & 3 \end{bmatrix}\quad\textsf{ and }\quad B = \begin{bmatrix} -1 & 4 & 3 & -2 \\ 2 & -3 & 0 & 1 \\ -6 & -3 & 5 & 1/2 \end{bmatrix}\]

To subtract these matrices, you can subtract the corresponding elements:

\[ A - B = \begin{bmatrix} 1 - (-1) & -3 - 4 & 5 - 3 & -4 - (-2) \\ 3 - 2 & 0 - 3 & -1/2 - 0 & 2 - 1 \\ -7 - (-6) & 8 - (-3) & 4 - 5 & 3 -1/2 \end{bmatrix} \] Then you can simplify the signs, \[ A-B= \begin{bmatrix} 1 + 1 & -3 - 4 & 5 - 3 & -4 + 2 \\ 3 - 2 & 0 - 3 & -1/2 & 2 - 1 \\ -7 + 6 & 8 + 3 & 4 - 5 & 3 - 1/2 \end{bmatrix} = \begin{bmatrix} 2 & -7 & 2 & -2 \\ 1 & -3 & -1/2 & 1 \\ -1 & 11 & -1 & 5/2 \end{bmatrix} \]

You saw earlier that you can only add and subtract matrices if they share the same dimensions. You can look to this non-example to see why this is the case.

NoteNon-example

\[ \begin{aligned} A &=\begin{bmatrix} 1 & 2 & -3 \\ 4/5 & 0 & 6 \end{bmatrix} \quad \textsf{(a }2 \times 3\textsf{ matrix)}\\[0.5em] B &=\begin{bmatrix} -8 & 8 \\ 0 & 11\end{bmatrix} \quad \textsf{(a }2 \times 2\textsf{ matrix)} \end{aligned} \]

Why can you not add \(A\) and \(B\)?

Matrix addition requires that each entry in one matrix corresponds to an entry in the other matrix. But, since:

  • Matrix \(A\) has dimensions \(2 \times 3\), that is, 2 rows and 3 columns
  • Matrix \(B\) has dimensions \(2 \times 2\), that is, 2 rows and 2 columns

they do not have the same dimensions. How you would attempt to calculate entries \((A+B)_{13}\) and \((B-A)_{23}\)?

Scalar multiplication

Sometimes you can multiply a matrix by a number or variable. This is called scalar multiplication.

NoteDefinition of scalar multipication with matrices

A scalar multiplication of a matrix \(A\), by a number or variable \(k\), is obtained by multiplying each entry in \(A\) by \(k\),

\[kA =[k \cdot a_{ij}]\]

You can now see a few examples of this.

NoteExample 6

Let’s multiply a \(3 \times 2\) matrix by a scalar.

\[A =\begin{bmatrix} 0 & 4/3 \\ -3 & \sqrt{2} \\ -7 & 12 \end{bmatrix} \quad\quad k=3\]

To scalar multiply this matrix by \(3\), you multiply each element by \(3\):

\[3A=\begin{bmatrix} {3 \cdot 0} & {3 \cdot 4/3} \\ {3 \cdot -3} & {3 \cdot \sqrt{2}} \\ {3 \cdot -7} & {3 \cdot 12} \end{bmatrix}=\begin{bmatrix} 0 & 4 \\ -9 & 3\sqrt{2} \\ -21 & 36 \end{bmatrix}\]

To scalar multiply this matrix by \(x\), you multiply each element by \(x\): \[xA=\begin{bmatrix} 0 & 4x \\ -9x & (3\sqrt{2})x \\ -21x & 36x \end{bmatrix}\]

NoteExample 7

Let’s multiply a \(1 \times 4\) matrix by a scalar.

\[A =\begin{bmatrix} -6 & 7/3 & \pi & 12 \end{bmatrix} \quad\quad k=-1/2\]

To multiply this matrix by \(-1/2\), you can multiply each element by \(-1/2\):

\[-\frac{1}{2}A=\begin{bmatrix} {-\frac{1}{2} \cdot -6} & {-\frac{1}{2} \cdot 7/3} & {-\frac{1}{2} \cdot \pi} & {-\frac{1}{2}\cdot 12} \end{bmatrix} =\begin{bmatrix} -3 & -7/6 & -\pi/2 & -6 \end{bmatrix}\]

Now you can combine your understanding of matrix addition and scalar multiplication to tackle questions that ask for both of these skills.

NoteExample 8

Let’s calculate \(A + 2B\), for \[A =\begin{bmatrix} -2 & 3 \\ 0 & 1 \\ \end{bmatrix} \quad\quad B =\begin{bmatrix} -1 & 2 \\ -1 & -3 \\ \end{bmatrix}\]

First, let’s work out \(2B\), \[2 B = \begin{bmatrix}\ 2 \cdot -1 & 2 \cdot 2 \\ 2 \cdot -1 & 2 \cdot -3 \end{bmatrix}\] By carrying out these multiplications, you can arrive at, \[2 B = \begin{bmatrix}\ -2 & 4 \\ -2 & -6 \end{bmatrix}\] Now \(A + 2 B\), \[A + 2B = \begin{bmatrix} -1 + (-2) & 2 +4 \\ -1 + (-2) & -3+(-6) \\ \end{bmatrix} = \begin{bmatrix} -3 & 6 \\ -3 & -9 \\ \end{bmatrix}\]

Tip

You can also multiply two matrices together; see Guide: Matrix multiplication for more.

Quick check problems

  1. Give the dimensions of the following matrices:

\[A = \begin{bmatrix} 3 \\ 7 \end{bmatrix} \quad\textsf{ and }\quad B = \begin{bmatrix} 0 & 4 & -2 \\ 1/3 & -5 & 6 \\ 8 & -3/7 & 2 \end{bmatrix} \quad\textsf{ and }\quad C = \begin{bmatrix} 1 & -6 \\ -4 & 2/3 \\ 0 & 5 \\ 7/8 & -9 \\ 0 & -2 \end{bmatrix}\]

Answers:

The dimension of \(A =\) \(\times\) .

The dimension of \(B =\) \(\times\) .

The dimension of \(C =\) \(\times\) .

  1. You are given five statements below. Decide whether they are true or false.
  1. For the matrix \(B\) in Q\(1\), the entry \(b_{21} = 1/3\). Answer: .

  2. In any \(3\times 3\) matrix \(C = [c_{ij}]\), then \(c_{13} = c_{31}\). Answer: .

  3. Any diagonal matrix is an identity matrix. Answer:

  4. You can only add or subtract matrices that share the same dimensions. Answer: .

  5. A matrix can be both upper and lower triangular. Answer:

  1. You are given \(D = \begin{bmatrix}1&-1\\0&4\end{bmatrix}\) and \(E=\begin{bmatrix}-4&1\\1&-4\end{bmatrix}\). Find the \((2,2)\)th entry of the matrix \(D-3E\).

Answer: The entry \([D-3E]_{22} =\) .

Further reading

For more questions on this topic, please go to Questions: Introduction to matrices.

For more operations of matrices outside of addition and scalar multiplications Guide: Matrix multiplication and [Guide: Transposing matrices].

Version history

v1.0: initial version created 04/25 by Jessica Taberner as part of a University of St Andrews VIP project.

This work is licensed under CC BY-NC-SA 4.0.

Feedback

Your feedback is appreciated and useful. Feel free to leave a comment here,
but please be specific with any issues you encounter so we can help to resolve them
(for example, what page it occured on, what you tried, and so on).