Learn

Matrices and Markov Chains

Contents

A matrix is a rectangle of numbers in rows and columns. Multiplying a matrix by a column of numbers gives a new column, so a matrix is a rule that turns one list into another, and a product of two matrices applies one rule after the other.

How are matrices described and added?

The order of a matrix is its number of rows, then its number of columns: 2 rows and 3 columns is a 2 × 3. An entry is named by its row, then its column.

Columns run down. Counting them second gives the order 2 × 3. Full lesson: The Order of a Matrix

Add or subtract two matrices entry by entry, so they must have the same order. To multiply a matrix by a number, multiply every entry by that number. See The order of a matrix and Adding, subtracting and scaling matrices.

Add entry by entry. The top left of the sum is 3 + 1 = 4. Full lesson: Adding, Subtracting and Scaling Matrices
A 2 × 2 and a 2 × 3 have no matching entries, so this sum cannot be done. Full lesson: Adding, Subtracting and Scaling Matrices

Now you

What goes in row 1, column 2 of A + B?

Multiply this matrix by 4. What goes in row 1, column 1?

How does matrix multiplication work, and why is AB not BA?

To multiply two matrices, pair a row of the left matrix with a column of the right: multiply matching entries and add the products. That sum is one entry of the product, and row 1 with column 1 fills row 1, column 1.

Pair row 1 with column 1: multiply each pair and add, 2 × 5 + 3 × 1 = 13. Full lesson: The Matrix Product

A row of A must be as long as a column of B, so AB exists only when A has as many columns as B has rows. A 2 × 3 times a 3 × 2 is a 2 × 2: the outer numbers give the order of the answer.

The rule is built this way because it totals a bill: a row of quantities times a column of prices is one shop's takings.

Shop A sold 4 pens at 3 and 2 pads at 5, so 4 × 3 + 2 × 5 = 22. Full lesson: Combining Data with a Matrix Product

Order matters. AB and BA are usually different matrices, and they can even have different orders: a 2 × 3 times a 3 × 2 is 2 × 2, but the product the other way round is 3 × 3. Matrix multiplication is not commutative.

So AB and BA are different matrices: matrix multiplication is not commutative. Full lesson: Why AB Differs from BA

The identity matrix I has ones down the main diagonal and zeros everywhere else, and multiplying by I changes nothing, just as multiplying a number by 1 does. The inverse of A is the matrix that multiplies with A to give I. A pattern in the powers of A is proved by induction: check the formula at n = 1, then multiply the assumed matrix by A once more. See The matrix product, Combining data with a matrix product, Why AB differs from BA, The identity and zero matrices and Matrix powers by induction.

Now you

Can this product be worked out?

What is the order of this product?

What does a determinant measure?

For the 2 × 2 matrix (a b; c d), the determinant is ad − bc: the product down the main diagonal minus the product along the other diagonal. For (4 2; 5 3) it is 12 − 10 = 2.

The determinant is the factor by which the matrix scales area, and a negative determinant also reflects. A determinant of 0 squashes the plane onto a line, so different points land on the same point and nothing can send them back apart. A matrix with determinant 0 has no inverse.

When the two products match, det = 0 and the matrix has no inverse. Full lesson: The Determinant of a 2 × 2 Matrix

When the determinant is not 0, the inverse of (a b; c d) takes three moves: swap a and d, change the signs of b and c, then divide every entry by ad − bc. Check by multiplying: the product is I.

Here ad − bc = 1, so the inverse of (3 5; 1 2) is (2 −5; −1 3). Full lesson: The Inverse of a 2 × 2 Matrix

The inverse solves simultaneous equations in one step. Write the pair as A X = b, with the coefficients in A, the unknowns in the column X and the constants in b, then multiply both sides on the left by A⁻¹ to leave X on its own.

Work out the product: the column that comes out is x = 2 and y = 1. Full lesson: Solving Simultaneous Equations with a Matrix Inverse

A 3 × 3 determinant expands along a row: each entry of row 1 multiplies the 2 × 2 determinant left when its row and column are deleted, with the signs +, −, +. It measures volume, and it is 0 exactly when there is no inverse. The 3 × 3 inverse is the transposed matrix of cofactors divided by the determinant, and it solves three equations in one step. See The determinant of a 2 × 2 matrix, The inverse of a 2 × 2 matrix, Solving simultaneous equations with a matrix inverse, The determinant of a 3 × 3 matrix, The inverse of a 3 × 3 matrix and Solving three equations with a matrix inverse.

Now you

What is the determinant of this matrix?

This matrix has no inverse. What is k?

What are eigenvalues and eigenvectors?

Most columns change direction when multiplied by A = (4 −1; 2 1), but (1, 1) comes back as (3, 3): the same direction, stretched by 3. A column that A only stretches is an eigenvector, and the factor is its eigenvalue: A v = λ v. Any multiple of an eigenvector is another, so an eigenvector names a direction. A negative eigenvalue reverses it, and 0 collapses it.

But (1, 1) comes back as (3, 3): the same direction, stretched three times. Full lesson: Eigenvalues and Eigenvectors

To find the eigenvalues, rewrite A v = λ v as (A − λI) v = 0. A non-zero column sent to zero means A − λI has no inverse, so det(A − λI) = 0. Subtracting λI takes λ off each diagonal entry, so here det(A − λI) = (4 − λ)(1 − λ) + 2 = λ² − 5λ + 6, the characteristic polynomial. Its roots, 2 and 3, are the eigenvalues.

Set it to zero and factor: the two eigenvalues of A are 2 and 3. Full lesson: The Characteristic Polynomial

For each eigenvalue, solve (A − λI) v = 0. At λ = 3 both rows give y = x, so v = (1, 1); at λ = 2 they give y = 2x, so v = (1, 2).

Put the eigenvectors as the columns of P and the eigenvalues, in the same order, on the diagonal of D. Then A P = P D, so A = P D P⁻¹. Powers follow, because every inner P⁻¹ P cancels: Aⁿ = P Dⁿ P⁻¹, and Dⁿ is found entry by entry. See Eigenvalues and eigenvectors, The characteristic polynomial, Finding an eigenvector, Diagonalizing a 2 × 2 matrix and Matrix powers by diagonalization.

So A⁵ is three products, not five: P, then the raised diagonal, then P⁻¹. Full lesson: Matrix Powers by Diagonalization

Now you

What does A − λI look like?

What is the characteristic polynomial of this matrix?

What is a Markov chain, and why does it settle down?

A Markov chain moves between a fixed set of states, and each move depends only on the current state, not on the history. Suppose each year 0.2 of a city's people move to the country and 0.3 of the country's people move to the city. Those shares fill a transition matrix T. Each column is one starting state, so its entries add to 1.

Multiply T by this year's split and next year's split comes out. After n years the split is Tⁿ times the start, and diagonalizing T makes Tⁿ easy to find.

Multiply T by this year’s split and the next year comes out: 550 and 450. Full lesson: Transition Matrices

A transition diagram shows the same numbers as arrows between the states, with a loop for the share that stays. A chain is regular when some power of T has every entry positive. A state whose only arrow loops back to itself traps everyone who enters it, so that chain is not regular.

Each arrow carries the share moving that way, and a loop carries the share that stays. Full lesson: Transition Diagrams

Start everyone in the city and the split settles. A settled split is one that T leaves unchanged, so it is an eigenvector of T with eigenvalue 1. Solve (T − I) s = 0: both rows give 2x = 3y, so the long-run split is 3 city to 2 country.

Start everyone in the city and the split settles: 800, 700, 650, 625. Full lesson: The Long-Run Steady State

Every transition matrix has eigenvalue 1, because its columns add to 1. The other eigenvalues are smaller than 1 in size, so their share of any start shrinks with each step, and the eigenvector for 1 is what remains. PageRank is this vector for the matrix of links between web pages. See Transition matrices, Transition diagrams and The long-run steady state.

Now you

80 percent of the city stays. What goes under it in column 1?

In a transition matrix, which group of entries adds to 1?

Where this leads

Matrix arithmetic says what a matrix does to a column, the determinant says whether that can be undone, and eigenvalues say what happens when the matrix is applied many times. A Markov chain is that last question asked about a matrix of probabilities.

The mistakes worth naming

Learn this properly in the app

Every lesson linked above is illustrated in Math Challenge, with worked examples and practice questions. Matrices acting on shapes continue in congruence, circle theorems and transformations, and the characteristic polynomial uses the factoring from quadratics and polynomials.

Your turn

Three to try — tap what you get.

Multiplying any matrix by the identity gives

The determinant of [[2, 1], [3, 4]]

Each row of a Markov transition matrix sums to

Math ChallengePractice that adapts to you, the whole lesson ladder, and your progress saved.
Start with Math Challenge

Mr. Chalk Practice this lesson in the app