topic badge
AustraliaVIC
VCE 12 General 2023

7.03 Matrix multiplication

Lesson

Matrix multiplication

Two matrices can be multiplied if the number of columns in the first matrix is equal to the number of rows in the second.

If matrix A has dimensions m \times n and matrix B has dimensions n \times p then the dimensions of AB will be \left(m\times n\right)\times \left(n\times p\right)=\left(m\times p\right).

If the dimensions do not meet this criteria then we say that the matrix multiplication is undefined.

Unlike matrix addition and subtraction, matrix multiplication is not computed element by element.

Let's look at an example of multiplication before we generalise the result.

If we take each element in the first row, and multiply it by the corresponding element in the first column, then add the three results, we end up with a number that belongs in the spot occupying the first row and first column.

The image shows two matrices highlighting the row and column that will be multiplied. Ask your teacher for more information.

So 5\times 6+12\times 1+56\times 7=434 goes into the (1,1) entry.

\begin{bmatrix} 5 & 12 & 56 \\ 10 & 30 & 75 \end{bmatrix} \begin{bmatrix} 6 & 3 \\ 1 & 2\\ 7 & 2 \end{bmatrix} = \begin{bmatrix} 434 & . \\ . & . \end{bmatrix}

The next combination will be the first row and the second column. Find the sum of each elements in the first row multiplied by the corresponding element in second column.

The image shows two matrices highlighting the row and column that will be multiplied. Ask your teacher for more information.

So, 5\times 3+12\times 2+56\times 2=151 goes into the (1,2) entry.

\begin{bmatrix} 5 & 12 & 56 \\ 10 & 30 & 75 \end{bmatrix} \begin{bmatrix} 6 & 3 \\ 1 & 2\\ 7 & 2 \end{bmatrix} = \begin{bmatrix} 434 & 151 \\ . & . \end{bmatrix}

The next combination will be the second row and the first column. Take the sum of each element in the second row multiplied by the corresponding element in first column.

The image shows two matrices highlighting the row and column that will be multiplied. Ask your teacher for more information.

So 10\times 6+30\times 1+75\times 7=615 goes into the (2,1) entry.

\begin{bmatrix} 5 & 12 & 56 \\ 10 & 30 & 75 \end{bmatrix} \begin{bmatrix} 6 & 3 \\ 1 & 2\\ 7 & 2 \end{bmatrix} = \begin{bmatrix} 434 & 151 \\ 615 & . \end{bmatrix}

The final combination is the second row and the second column. Take the sum of each element in the second row multiplied by the corresponding element in second column.

The image shows two matrices highlighting the row and column that will be multiplied. Ask your teacher for more information.

So 10\times 3+30\times 2+75\times 2=240 goes into the (2,2) entry.

\begin{bmatrix} 5 & 12 & 56 \\ 10 & 30 & 75 \end{bmatrix} \begin{bmatrix} 6 & 3 \\ 1 & 2\\ 7 & 2 \end{bmatrix} = \begin{bmatrix} 434 & 151 \\ 615 & 240 \end{bmatrix}

In general, to compute element (i,j) in the matrix AB, we multiply the elements of the ith row in A with the elements in the jth column of B, and sum all the products. For a pair of 2\times 2 matrices, this looks like this: \begin{bmatrix} a&b\\ c&d \end{bmatrix} \begin{bmatrix} e&f\\ g&h \end{bmatrix} =\begin{bmatrix} ae+bg&af+bh\\ ce+dg&cf+dh \end{bmatrix}

Examples

Example 1

ConsiderA = \begin{bmatrix} -1 & -3 \\ -9 & -4 \\ 4 & -5 \end{bmatrix} and B = \begin{bmatrix} 3 \\ -8 \end{bmatrix}

a

Is the product AB defined?

Worked Solution
Create a strategy

Check whether the number of columns in A is equal to the number of rows in B.

Apply the idea

Matrix A has dimensions 3\times 2 and matrix B has dimensions 2\times 1.

Since the number of columns of matrix A is equal to the number of rows of matrix B, then it means that the product AB is defined.

b

What are the dimensions of AB?

Worked Solution
Create a strategy

When you multiply an m\times n and an n\times r matrix, the result is an m\times r matrix.

Apply the idea

When matrix A with dimensions 3\times 2 is multiplied by matrix B with dimensions 2\times 1 then AB will have dimensions 3\times 1.

c

Determine the matrix AB.

Worked Solution
Create a strategy

To compute the element (i,j), multiply the elements of the ith row in A with the elements in the jth column of B, and sum all the products.

Apply the idea
\displaystyle AB\displaystyle =\displaystyle \begin{bmatrix} -1 & -3 \\ -9 & -4 \\ 4 & -5 \end{bmatrix}\begin{bmatrix} 3 \\ -8 \end{bmatrix}Multiply matrix A by matrix B
\displaystyle =\displaystyle \begin{bmatrix} -1 \times 3 + (-3\times (-8))\\ -9\times 3 +(-4 \times (-8))\\ 4\times 3 + (-5 \times (-8)) \end{bmatrix}Multiply and add corresponding elements
\displaystyle =\displaystyle \begin{bmatrix} 21\\ 5\\ 52 \end{bmatrix}Evaluate each element

Example 2

An organic gardener produces lettuces and tomatoes. The following table indicates the time taken for the growing stages of each plant.

Stage 1 Germination from seed (days)Stage 2 From sprout to seedling (days)Stage 3 From seedling to maturity (days)
Lettuce51256
Tomato103075

The amount of water per day needed for Stage 1 is 60 \text{ mL}, for Stage 2 is 40 \text{ mL}, and Stage 3 is 30 \text{ mL}.

Use matrix multiplication to calculate the amount of water needed for both the lettuce and tomato.

Worked Solution
Create a strategy

Construct two matrices to work out the multiplication.

Apply the idea

Let D be the matrix of days needed in each stage, where it has a 2 \times 3 matrix.

D= \begin{bmatrix} 5 & 12 & 56\\ 10 & 30 & 75 \end{bmatrix}

Let W be the matrix of water needed, where it has a 3 \times 1 matrix.

W= \begin{bmatrix} 60 \\ 40 \\ 30 \end{bmatrix}

\displaystyle \text{Amount of water}\displaystyle =\displaystyle \begin{bmatrix} 5 & 12 & 56\\ 10 & 30 & 75 \end{bmatrix} \times \begin{bmatrix} 60 \\ 40 \\ 30 \end{bmatrix} Multiply matrix D by matrix W
\displaystyle =\displaystyle \begin{bmatrix} 5 \times 60 + 12 \times 40 + 56 \times 30 \\ 10 \times 60 + 30 \times 40 + 75 \times 30 \end{bmatrix} Multiply and add corresponding elements
\displaystyle =\displaystyle \begin{bmatrix} 2640 \\ 4050 \end{bmatrix} Evaluate each element

This means 2640 \text{ mL} of water is needed to raise lettuce while 4050 \text{ mL} of water is used to needed tomatoes.

Idea summary

If matrix A has dimensions m \times n and matrix B has dimensions n \times p then the dimensions of AB will be \left(m\times n\right)\times \left(n\times p\right)=\left(m\times p\right).

To compute an element, multiply the row elements by the corresponding column elements and add their products.

Multiplicative identity

The identity matrix, I, has similar properties to the number 1 in the real number system. When multiplying a matrix by the identity matrix, I, of the appropriate order, the result is the original matrix.

\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}

The diagonal matrix, with 1's on the diagonal is the identity matrix. Use the symbol I, to represent the identity matrix.

\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = I

A special thing about the identity matrix is that the order of multiplication doesn't matter, i.e.

\text{ Let $A= \begin{bmatrix} a & b \\ c & d \end{bmatrix}$ and let $I= \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}$ then $AI= IA = A$. }

Examples

Example 3

Find the matrix that satisfies the following equation:

\begin{bmatrix} 6 & 1 \\ 5 & 9 \end{bmatrix} \times \begin{bmatrix} ⬚ & ⬚ \\ ⬚ & ⬚ \end{bmatrix} = \begin{bmatrix} 6 & 1 \\ 5 & 9 \end{bmatrix}

Worked Solution
Create a strategy

Check whether the product of the matrices is the same as the first matrix.

Apply the idea

Since the first matrix and product matrix are the same, the second matrix is the identity matrix I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}.

\begin{bmatrix} 6 & 1 \\ 5 & 9 \end{bmatrix} \times \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} 6 & 1 \\ 5 & 9 \end{bmatrix}

Idea summary

The multiplicative identity for matrices is the Identity matrix I. For any matrix A,

AI=IA=A

Multiplication and transpose of a matrix

A matrix is transposed by interchanging its rows and columns.

We explore what happens if the matrix product is transposed. What is (AB)^T?

The product AB=C is obtained by finding all the elements of the matrix c_{i,j}, where we multiply the elements of the ith row of A with the jth column of B, and then sum the products.

The corresponding entry of C^T must be c_{j,i} and this is found by multiplying the elements of the jth row of B^T with the elements of the ith column of A^T, and then summing the products.

Therefore, C^T=B^TA^T. In other words:

\left(AB\right)^T=B^TA^T

For instance, consider the following matrices A and B as well as the matrix product AB.

A = \begin{bmatrix} 1 & 2 & 4 \\ 2 & 1 & 0 \end{bmatrix}, B = \begin{bmatrix} 1 & 2\\ 2 & 3\\ 3 & 1 \end{bmatrix}, AB = \begin{bmatrix} 17 & 12\\ 4 & 7 \end{bmatrix}

Then the transpose of the matrix product AB is given by interchanging the rows and columns:

(AB)^T = \begin{bmatrix} 17 & 4\\ 12 & 7 \end{bmatrix}

To find the matrix (AB)^T, we can also multiply the transpose of the matrices B and A.

We take the transposes of A and B and form the product B^TA^T.

B^T= \begin{bmatrix} 1 & 2 & 3 \\ 2 & 3 & 1 \end{bmatrix}, A^T = \begin{bmatrix} 1 & 2\\ 2 & 1\\ 4 & 0 \end{bmatrix}, B^TA^T = \begin{bmatrix} 17 & 4\\ 12 & 7 \end{bmatrix}

The matrix B^TA^T is the same as (AB)^T.

Examples

Example 4

Consider the following questions below.

a

If A = \begin{bmatrix} -1 & 4 & 6 & -5 \\ -1 & -7 & -4 & -8 \end{bmatrix}, then A^T = \begin{bmatrix} ⬚ & ⬚ \\ ⬚ & ⬚ \\ ⬚ & ⬚ \\ ⬚ & ⬚ \end{bmatrix}.

Worked Solution
Create a strategy

Transpose the matrix by interchanging the rows and columns.

Apply the idea

Let the rows of A become columns of A^T or columns of A become rows of A^T.

\begin{bmatrix} -1 & 4 & 6 & -5 \\ -1 & -7 & -4 & -8 \end{bmatrix} \to A^T = \begin{bmatrix} -1 & -1 \\ 4 & -7 \\ 6 & -4 \\ -5 & -8 \end{bmatrix}

b

The product A\times A^T exists. Is this statement true or false?

Worked Solution
Create a strategy

Check whether the number of columns in A is equal to the number of rows in A^T.

Apply the idea

Matrix A has dimensions 2\times 4 and matrix A^T has dimensions 4\times 2.

Since the number of columns of matrix A is equal to the number of rows of matrix A^T, then it means that the statement is true.

c

What is the order of the resulting matrix after evaluating A\times A^T?

Worked Solution
Create a strategy

The order is the dimensions of the product of the matrices.

Apply the idea

Matrix A has dimensions 2 \times 4 and matrix A^T has dimensions 4 \times 2, then A \times A^T will have dimensions or order of 2 \times 2.

d

Evaluate the matrix multiplication:

A\times A^T = \begin{bmatrix} ⬚ & ⬚ \\ ⬚ & ⬚ \end{bmatrix}

Worked Solution
Create a strategy

To compute the element (i,j), multiply the elements of the ith row in A with the elements in the jth column of A^T, and sum all the products.

Apply the idea

Since the elements that will be multiplied at the first and last rows are just the same, we can square each element to compute quickly.

\displaystyle A \times A^T\displaystyle =\displaystyle \begin{bmatrix} -1 & 4 & 6 & -5 \\ -1 & -7 & -4 & -8 \end{bmatrix} \begin{bmatrix} -1 & -1 \\ 4 & -7 \\ 6 & -4 \\ -5 & -8 \end{bmatrix}Multiply matrix A by matrix A^T
\displaystyle =\displaystyle \begin{bmatrix} (-1)^2 + 4^2 + 6^2 + (-5)^2 & . \\ . & . \end{bmatrix} Compute the first element
\displaystyle =\displaystyle \begin{bmatrix} 78 & . \\ . & . \end{bmatrix} Evaluate the first element
\displaystyle =\displaystyle \begin{bmatrix} 78 & (-1 \times -1) + (4 \times -7) + (6 \times -4) + (-5 \times -8)\\ . & . \end{bmatrix} Compute the second element
\displaystyle =\displaystyle \begin{bmatrix} 78 & -11 \\ . & . \end{bmatrix} Evaluate the second element
\displaystyle =\displaystyle \begin{bmatrix} 78 & -11\\ (-1 \times -1) + (-7 \times 4) + (-4 \times 6) + (-8 \times -5) . & . \end{bmatrix} Compute the third element
\displaystyle =\displaystyle \begin{bmatrix} 78 & -11 \\ -11 & . \end{bmatrix} Evaluate the third element
\displaystyle =\displaystyle \begin{bmatrix} 78 & -11 \\ -11 & (-1)^2 + (-7)^2 + (-4)^2 +(-8)^2 \end{bmatrix} Compute the last element
\displaystyle =\displaystyle \begin{bmatrix} 78 & -11 \\ -11 & 130 \end{bmatrix} Evaluate the last element
Idea summary

To find the transpose of a product of two matrices, take the tranpose of each matrix then multiply the transposed matrices.

For instance, (AB)^T=B^TA^T.

Powers of matrices

Any square matrix, let's call it A, can be multiplied by itself and the result is a square matrix of the same dimension, which we can call B.

So, we can write A_{n\times n}\times A_{n\times n}=B_{n\times n} or, more simply, A^2=B.

The process can be extended: A^3=A\times A^2=A^2\times A, and so on. If we have A multiplied by itself n times it does not matter which pairs of matrices is multiplied first or in what order all the other multiplications are carried out.

This is important to note because it contrasts with matrix multiplication generally, where AB is not necessarily the same as BA.

There are applications in which powers of matrices arise naturally. Suppose a process can be represented by a matrix multiplying a vector of coordinates. This is called a linear transformation.

For example, if a matrix A_{(n\times n)} multiplies a vector \mathbf{v}_{(n\times 1)} to give a vector \mathbf{u}_{(n\times 1)}, we would write the matrix equation A\mathbf{v}=\mathbf{u}.

It may then be of interest to apply the same transformation to the vector \mathbf{u}, and to go on repeatedly applying the transformation to the previous result. This generates a sequence of vectors:

A\mathbf{v},A\left(A\mathbf{v}\right),A\left(A\left(A\mathbf{v}\right)\right),...

The nth iteration of this process is just A^n\mathbf{v}.

In the transformation \mathbf{u}=B\mathbf{v}, the matrix B= \begin{bmatrix} \frac{\sqrt 3}{2} & -\frac 12\\ \frac 12 & \frac{\sqrt 3}{2} \end{bmatrix} has the effect of rotating a vector \mathbf{v} in the plane anticlockwise through an angle of 30\degree without changing the length of the vector.

We would expect that twelve applications of this transformation of vector \mathbf{v} should bring it back to its original position and therefore, B^{12} should be the identity matrix.

You should check by hand that

B = \begin{bmatrix} \frac{\sqrt 3}{2} & -\frac 12\\ \frac 12 & \frac{\sqrt 3}{2} \end{bmatrix}, B^2= \begin{bmatrix} \frac 12 & -\frac{\sqrt 3}{2}\\ \frac{\sqrt 3}{2} & \frac 12 \end{bmatrix}, B^3= \begin{bmatrix} 0 & -1\\ 1 & 0 \end{bmatrix}, B^6= \begin{bmatrix} -1 & 0\\ 0 & -1 \end{bmatrix},

and squaring B^6 gives B^{12}=I.

If you now carry out the calculation of B^{12} by calculator using the same sequence of matrix multiplications but with decimal approximations for the entries, does your device confirm that B^{12}=I?

Examples

Example 5

Given the 4\times 4 matrix A, calculate A^{15}. Round each element to three decimal places.

A= \begin{bmatrix} 0 & 0.4 & 0.7 & -0.1 \\ 0.9 & 0.8 & -0.7 & 0.2 \\ -0.1 & 0.5 & 0.5 & 0.1 \\ 0 & 0.2 & 0.2 & 0.6 \end{bmatrix}

Worked Solution
Create a strategy

Use technology when raising a square matrix with higher powers.

Apply the idea

A^{15}= \begin{bmatrix} 1.758 & 2.128 & -0.283 & 0.438 \\ 2.170 & 2.626 & -0.349 & 0.541 \\ 1.759 & 2.128 & -0.283 & 0.439 \\ 1.555 & 1.882 & -0.250 & 0.388 \end{bmatrix}

Idea summary

A matrix can only be raised to a power when it is square.

A square matrix of order n can be written as A_n.

Number of routes with matrices

Different routes from A to G in a network showing 3 edges from A going to F. Ask your teacher for more information.

Matrices can be used to help us answer questions such as the following: How many different routes are there from A to F that use exactly 3 edges in the network shown? Three routes are shown.

Different routes from A to G in a network showing same edges more than once from A to F. Ask your teacher for more information.

But there are many more, including some that use the same edge more than once. Here are two more.

It can be just as hard to know when to stop looking as it is to find them all. Instead, we are going to use the network's adjacency matrix to answer this for us. Let’s start by writing it out.

If two vertices are connected by an edge, there is a 1 in their corresponding row and column. If they are not connected, there is a 0 instead.

\begin{array}{cc} &\begin{array}{ccc} A&B&C&D&E&F&G \end{array} \\ \begin{array}{c} A \\ B \\ C \\D\\E\\F\\G \end{array} & \left( \begin{array}{ccc} 0&1&0&1&\,1&\,\,1&\,\,\,0\\ 1&0&1&0&\,0&\,\,0&\,\,\,0 \\ 0&1&0&0&\,0&\,\,1&\,\,\,1 \\ 1 &0&0&0&\,1&\,\,1&\,\,\,1 \\ 1&0&0&1&\,0&\,\,1&\,\,\,0 \\ 1&0&1&1&\,1&\,\,0&\,\,\,0 \\ 0&0&1&1&\,0&\,\,0&\,\,\,0 \end{array}\right) \end{array}

The number of routes of length n in a network from one vertex to another is equal to the entry in the start vertex’s row and end vertex’s column of the matrix M^n, where M is the adjacency matrix for the network.

Since we are asking about a route of length 3, we need to cube the matrix above.Using a calculator or an online tool we get the result:

\begin{array}{cc} & \begin{array}{ccc} A&B&C&D&E&F&G \end{array} \\ \begin{array}{c} A \\ B \\ C \\D\\E\\F\\G \end{array} & \left( \begin{array}{ccc} 6&6&3&9&8&10&4 \\ 6&0&5&4&3&2&1 \\ 3&5&0&3&4&8&5 \\ 9&4&3&6&8&10&6 \\ 8&3&4&8&6&8&3 \\ 10&2&8&10&8&6&2 \\ 4&1&5&6&3&2&0 \end{array}\right) \end{array}

A 7 by 7 matrix where the element for row A column F is 10. Ask your teacher for more information

We then look for the entry in row A, column F, to find our answer.

So there are 10 routes from A to F of length 3.

We don't know what the routes are, but if we do go looking for them and find 10 of them, we know we can stop looking.

This same idea works for directed networks as well. Consider the network below:

Network with nodes A to E and a 5 by 5 matrix with rows and columns labelled A to E. Ask your teacher for more information.
A 5 by 5 matrix where rows and columns  are labelled A to E. Ask your teacher for more information.

How many routes are there from C to B of length 7? We need to take the 7th power of the adjacency matrix which is shown.

We can then read off the answer by looking in row C, column B, to see that there are 43 different routes of length 7 from C to B in this network.

Examples

Example 6

A network connecting Kingston, Ashland, Greenville and Dunham. Ask your teacher for more information.

The matrix A represents all of the single-step paths (routes of length 1) between the towns in the network shown. A = \begin{bmatrix} 1 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \end{bmatrix} Both the rows and columns are in the order: Kingston, Ashland, Greenville and then Dunham.

a

Find A^{4}, the matrix that represents all possible four-step paths between the towns. Use technology to calculate A^4.

Worked Solution
Create a strategy

Use technology to calculate A^4.

Apply the idea
\displaystyle A^4\displaystyle =\displaystyle \begin{bmatrix} 15&7&10&7\\ 7&9&2&9\\ 10&2&8&2\\ 7&9&2&9\\ \end{bmatrix}
b

How many four-step paths can be taken from Ashland to Dunham?

Worked Solution
Create a strategy

Find the entry that is in the row for Ashland and the column for Dunham.

Apply the idea

From the original matrix A, the second row represents leaving from Ashland, and the fourth column represents going to Dunham.

The entry at the second row and fourth column of A^4 is 9.

There are 9 four-step paths from Ashland to Dunham.

Idea summary

The number of routes of length n in a network from one vertex to another is equal to the entry in the start vertex’s row and end vertex’s column of the matrix M^n, where M is the adjacency matrix for the network.

Outcomes

U4.AoS2.1

the order of a matrix, types of matrices (row, column, square, diagonal, symmetric, triangular, zero, binary, permutation and identity), the transpose of a matrix, and elementary matrix operations (sum, difference, multiplication of a scalar, product and power)

What is Mathspace

About Mathspace