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?
A matrix is described by its order: the number of rows, then the number of columns, so 2 rows and 3 columns make a 2 × 3 matrix. An entry is named by its row, then its column: sits in row 2, column 1. Matrices are added entry by entry, so they must have the same order. Writing rows with a semicolon between them, (1 4; 2 0) + (3 −1; 5 2) = (4 3; 7 2), since 1 + 3 = 4, 4 − 1 = 3, 2 + 5 = 7 and 0 + 2 = 2. This works because each position holds the same kind of quantity in both, such as one shop's sales of one item. Matrices of different orders cannot be added, since some entries would have no partner. A scalar multiplies every entry: 3 times (1 4; 2 0) is (3 12; 6 0). Check a sum by subtracting one matrix to recover the other.
multiplication is commutative: 3 × 4 = 4 × 3
Make 24 as a rectangle, then find another factor pair
See The order of a matrix and 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 each row of the left matrix with each column of the right: multiply matching entries and add the products. For A = (1 2; 3 4) and B = (0 1; 1 0), row 1 of A with column 1 of B gives 1 × 0 + 2 × 1 = 2, and the full product is AB = (2 1; 4 3). The rule makes a product mean one transformation followed by another. AB usually differs from BA: BA = (3 4; 1 2), since B swaps the rows of A, while AB swaps its columns. Sizes can block a product: AB exists only when A has as many columns as B has rows, so a 2 × 3 times a 3 × 2 is a 2 × 2. Check one entry of BA: row 1 of B with column 1 of A gives 0 × 1 + 1 × 3 = 3.
A row of A must be as long as a column of B, and the outer numbers of the two orders 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.
The other way round, a 3 × 2 times a 2 × 3 is a 3 × 3, so the two products need not even have the same order. Matrix multiplication is not commutative.
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 a 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. It is the factor by which the matrix scales area. For (4 2; 5 3) the determinant is 4 × 3 − 2 × 5 = 12 − 10 = 2, so the unit square becomes a parallelogram of area 2. The formula gives area because the columns (4, 5) and (2, 3) are the sides of that parallelogram, and ad − bc is its area with a sign. A negative determinant means a reflection too. A determinant of 0 changes everything: the plane is squashed onto a line or a point, so the matrix has no inverse, as with (2 4; 1 2), where 2 × 2 − 4 × 1 = 0. Check: a shape of area 3 maps to area 3 × 2 = 6.
det [[a, b], [0, 1]] = a × 1 − b × 0 = a, so b never appears: a shear leaves the area unchanged
Make the determinant 2
When it is 0, different points land on the same point, and nothing can send them back apart.
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.
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 to leave X on its own.
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?
Does this matrix have an inverse?
What are eigenvalues and eigenvectors?
An eigenvector of a square matrix A is a nonzero column that A only stretches, and the stretch factor is its eigenvalue: . Most columns change direction when multiplied by A = (4 −1; 2 1), but (1, 1) comes back as (3, 3), because 4 × 1 − 1 × 1 = 3 and 2 × 1 + 1 × 1 = 3, so (1, 1) is an eigenvector with eigenvalue 3. Any multiple of an eigenvector is another, so an eigenvector names a direction. A negative eigenvalue reverses it, and 0 collapses it. Eigenvectors matter because along them the matrix acts like plain multiplication, so powers are easy: applying A five times stretches (1, 1) by . Finding them starts from the eigenvalues, the solutions of , and each eigenvalue then gives a direction. Test a claimed eigenvector: A times (1, 2) is (2, 4), twice the column, so the other eigenvalue is 2.
Av points 16° away from v, so Av ≠ λv: A turns this vector as well as stretching it, and it is not an eigenvector
Rotate v until Av lies on the same line as v
To find the eigenvalues, rewrite as . A non-zero column sent to zero means has no inverse, so . Subtracting takes off each diagonal entry, so here , the characteristic polynomial. Its roots, 2 and 3, are the eigenvalues.
For each eigenvalue, solve . At both rows give y = x, so v = (1, 1); at 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 . Powers follow, because every inner cancels: , and 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.
Now you
What does 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. The move chances fill a transition matrix T, and T times one year's split gives the next. 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. Each column of T is one starting state, so its entries add to 1. From 500 in each place, next year's city holds 400 + 150 = 550, since of 500 stay and of 500 arrive. A regular chain settles because T leaves one split unchanged, and every other part of the start shrinks at each step. Here that split has equal flows each way, which puts of everyone in the city. A trap state, which nobody leaves, eventually holds everyone who can reach it. Test the settled split: of of 400.
the split is still 60 percentage points from 40/60, and the gap halves at every step: (a₀ − 0.4) × 0.5ᵗ
Start with everything in A, then step time forward until the split freezes
After n years the split is times the start, and diagonalizing T makes easy to find.
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.
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.
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
- Multiplying entry by entry. The matrix product pairs each row of the left matrix with each column of the right.
- Assuming AB = BA. Work out both.
- Canceling a matrix. AB = AC gives B = C only when A has an inverse.
- Treating a zero determinant as a small answer. It means the matrix has no inverse.
Matrices acting on shapes continue in congruence, circle theorems and transformations, and the characteristic polynomial uses the factoring from quadratics and polynomials. Related guides: Applications of Integration and Polar Curves and Complex Numbers.
Your turn
Three to try — tap what you get.
Multiplying any matrix by the identity gives
The determinant of [[2, 1], [3, 4]]
Each column of a Markov transition matrix sums to
Questions and answers
- Why is AB not the same as BA for matrices?
- Because a matrix represents an action, and actions do not generally commute. Rotating a book ninety degrees and then flipping it leaves it in a different position from flipping it first and then rotating. Matrix multiplication was defined to compose actions in sequence, so it inherits that order-dependence. For some pairs AB does equal BA, but it is a coincidence about those particular matrices, not a rule.
- What does the determinant of a matrix tell you?
- It is the factor by which the matrix scales area, in two dimensions, or volume in three. A determinant of 3 means every region comes out three times as large, and a negative determinant means the matrix also flipped orientation. A determinant of zero means the matrix squashed everything flat, which is why a matrix with zero determinant has no inverse: information was destroyed and cannot be recovered.
- How do you use a matrix to solve simultaneous equations?
- Write the system as a matrix of coefficients multiplied by a column of unknowns equalling a column of constants, then multiply both sides by the inverse matrix. The unknowns column is left alone on one side, so one inverse and one multiplication produce every unknown at once. If the determinant is zero the inverse does not exist, which corresponds exactly to the system having either no solution or infinitely many.
- What is an eigenvector, in plain terms?
- An eigenvector is a direction that the matrix does not turn — it only stretches or shrinks whatever lies along it. The factor by which it stretches is the eigenvalue. Most directions get rotated when a matrix acts on them; the eigenvectors are the special ones left pointing the same way, and they are what a repeated action eventually lines everything up with.
- What is a Markov chain?
- It is a model of a system that moves between a fixed set of states, where the chance of each next move depends only on the current state and not on the history. The probabilities are stored in a transition matrix, and multiplying by that matrix advances the model one step. Weather models, customer churn, board game positions and text prediction are all commonly modeled this way.
- Why does a Markov chain settle down to a steady state?
- Because repeated multiplication by the transition matrix pulls any starting distribution toward the matrix's dominant eigenvector. Every transition matrix has an eigenvalue of exactly 1, and the corresponding eigenvector is the distribution that the chain reproduces unchanged. Other components shrink with each step, so after enough steps the starting point stops mattering.