Leaving Certificate Applied Mathematics2.4 Matrix algebra and the product of adjacency matrices

All books

2.4 Matrix algebra and the product of adjacency matrices — Learn

Prerequisites: Section 2.3 — adjacency matrices; multiplying whole numbers.

Objectives: multiply two matrices; explain what a power of an adjacency matrix counts; read the number of walks of a given length off a matrix power.

By the end of this section you can answer a question about routes by arithmetic on a matrix, without looking at the drawing at all.

Multiplying two matrices

To multiply matrix AA by matrix BB, take a row of AA and a column of BB: multiply the pairs, then add.

(AB)ij=∑kAikBkj(AB)_{ij} = \sum_k A_{ik} B_{kj}

Here kk runs over every column of the first matrix, which is every row of the second.

The entry in row ii, column jj of the product is row ii of the first matrix times column jj of the second.

Example 1. Work out (1234)(0110)\begin{pmatrix} 1&2\\ 3&4 \end{pmatrix}\begin{pmatrix} 0&1\\ 1&0 \end{pmatrix}.

  • Row 1, column 1: 1×0+2×1=21 \times 0 + 2 \times 1 = 2
  • Row 1, column 2: 1×1+2×0=11 \times 1 + 2 \times 0 = 1
  • Row 2, column 1: 3×0+4×1=43 \times 0 + 4 \times 1 = 4
  • Row 2, column 2: 3×1+4×0=33 \times 1 + 4 \times 0 = 3
(1234)(0110)=(2143)\begin{pmatrix} 1&2\\ 3&4 \end{pmatrix}\begin{pmatrix} 0&1\\ 1&0 \end{pmatrix} = \begin{pmatrix} 2&1\\ 4&3 \end{pmatrix}

Matrix multiplication is not commutative: ABAB and BABA are usually different, so the order matters. (Here BABA is the same, which is a special case.)

What a power of an adjacency matrix counts

Now the idea the whole section is for.

The walk-counting rule. In an adjacency matrix MM, the entry in row ii, column jj of MnM^n is the number of walks of length nn from vertex ii to vertex jj.

A walk of length nn uses nn edges, and vertices may repeat.

Why it is true. Look at M2M^2 first. A walk of length 2 from ii to jj goes i→k→ji \to k \to j for exactly one middle vertex kk. The walk exists when ii is joined to kk and kk is joined to jj — that is, when Mik=1M_{ik} = 1 and Mkj=1M_{kj} = 1, so their product is 11. The product of the two matrices adds that product over every possible middle vertex kk:

(M2)ij=∑kMikMkj(M^2)_{ij} = \sum_k M_{ik} M_{kj}

So it counts exactly the middle vertices that work, which is exactly the number of walks. The same argument repeats for M3M^3, and for every higher power.

Example 2. A network has vertices A,B,C,DA, B, C, D and edges ABAB, ACAC, BCBC, CDCD, so

M=(0110101011010010)M = \begin{pmatrix} 0&1&1&0\\ 1&0&1&0\\ 1&1&0&1\\ 0&0&1&0 \end{pmatrix}

Then

M2=(2111121111301101)M^2 = \begin{pmatrix} 2&1&1&1\\ 1&2&1&1\\ 1&1&3&0\\ 1&1&0&1 \end{pmatrix}

Read three facts off it.

  • The entry in row AA, column AA is 22, so there are 2 walks of length 2 from AA back to AA: A→B→AA \to B \to A and A→C→AA \to C \to A.
  • The entry in row AA, column DD is 11, so there is exactly 1 walk of length 2 from AA to DD: A→C→DA \to C \to D. There is no edge ADAD, so you must go through a middle vertex, and only CC is joined to both.
  • The diagonal entries count the walks that return to where they started. A vertex of degree dd has dd such walks of length 2, because it can go out along any edge and back along the same one. AA has degree 22, and indeed MAA2=2M^2_{AA} = 2.

Higher powers

The rule holds for every power.

Example 3. For the same MM,

M3=(2341324144231130)M^3 = \begin{pmatrix} 2&3&4&1\\ 3&2&4&1\\ 4&4&2&3\\ 1&1&3&0 \end{pmatrix}

so there are 4 walks of length 3 from AA to CC, and 1 from AA to DD.

Two useful checks:

  • The total of all the entries of MnM^n is the number of walks of length nn in the whole network, starting anywhere and ending anywhere.
  • The entry on the diagonal of M2M^2 is the degree of that vertex. If it is not, the matrix has been multiplied wrongly.

Progress check

Back to the chapter problem. Take your seven-room adjacency matrix from Section 2.3 and work out M2M^2.

Use it to answer one question that the drawing makes awkward: how many ways are there to travel from one particular room to another using exactly two cable runs? Read the entry in that row and column. Then check one entry against the drawing by hand, to be sure the rule is doing what it claims.

Keep MM and M2M^2. Section 2.8 searches the weighted version of this network for the shortest route, which is a different question from how many routes there are.

You should now be able to

Settings

Colour scheme

Light or dark pages. Your colour and layout stay the same.

Colour

The paper, ink and lettering. Your layout stays the same.

Quiet colours
Bold colours
Layout

How pages are arranged. Your colours stay the same.

Reading offline

Keep this book on this device and read it offline.