Markov Chains
If it’s sunny today, how likely is rain in three days? If customers switch phone companies every year, what share will each company have in the long run? A Markov chain models a system that moves between a few states in steps, where the chance of moving to each state depends only on the state it’s in now. Matrices make the calculations quick: one matrix multiplication moves the whole system forward one step.
Key ideas
Section titled “Key ideas”States and transition diagrams
Section titled “States and transition diagrams”A Markov chain has a set of states (for example, “sunny” and “rainy”) and, at each step, moves from its current state to another state (or stays put) with fixed probabilities. These transition probabilities depend only on the current state, not on how the system got there.
A transition diagram shows the states as circles and each possible move as an arrow labelled with its probability. The probabilities on the arrows leaving each state add up to .
The transition matrix
Section titled “The transition matrix”The transition matrix holds all the transition probabilities. This page uses the convention in the IB guide:
is the probability of moving from state to state .
So each column is a “from” state and each row is a “to” state, and each column adds up to . For the weather diagram, with the states in the order sunny, rainy:
Some textbooks and websites use the opposite convention (rows are “from” states and rows add to ). Their matrices are the transpose of these, and they multiply in the other order. Stick to the column convention in IB work, and label your states.
State matrices
Section titled “State matrices”A state matrix (column vector) gives the probability of being in each state after steps. The initial state matrix describes the start. For example, “it’s sunny today” is , and “there’s a chance of rain today” is . The entries of a state matrix add up to . A state matrix can also hold numbers or proportions of a population (like the number of customers of each company) instead of probabilities.
To move one step forward, multiply by on the left: , , and in general
Powers of the transition matrix
Section titled “Powers of the transition matrix”The entries of are the probabilities of moving between states in exactly steps: is the probability of being in state after steps, starting from state . Use your GDC’s matrix functions to find powers.
Regular chains and the steady state
Section titled “Regular chains and the steady state”A Markov chain is regular if some power has all entries positive (greater than ). That means it’s possible to get from every state to every state in exactly steps.
For a regular chain, as gets large:
- settles down to a steady state that does not depend on the initial state
- every column of gets closer and closer to .
The steady state is the state matrix that doesn’t change when you multiply by :
There are two ways to find it:
- Repeated multiplication: compute for a large (like ) on your GDC. Each column is (approximately) the steady state.
- Solving equations: write as a system of linear equations, replace one of them with “the entries add to ”, and solve. This gives exact answers. Exam questions say when exact values are required.
In the language of eigenvalues and eigenvectors, says that the steady state is an eigenvector of with eigenvalue , scaled so its entries add to .
Not every chain is regular. For , the system just flips between the two states forever, and the powers of alternate between and the identity matrix, so they never have all entries positive.
Worked examples
Section titled “Worked examples”Example 1: Writing a transition matrix
Section titled “Example 1: Writing a transition matrix”Use the weather model in the diagram. It’s sunny on Monday.
- (a) Write the transition matrix and the initial state matrix .
- (b) Find the probability that it is sunny on Tuesday, and on Wednesday.
Solution.
(a) With the states in the order sunny (S), rainy (R), the column for “from S” holds the probabilities (to S) and (to R):
Check: each column adds to .
(b) Tuesday is one step later:
Wednesday is two steps later:
The probability that it is sunny is on Tuesday and on Wednesday.
Check with a tree: sunny on Wednesday happens by S → S → S or S → R → S, with probability . ✓
Example 2: Powers of the transition matrix
Section titled “Example 2: Powers of the transition matrix”For the same weather model:
- (a) Find .
- (b) It is sunny today. Find the probability that it is rainy in days’ time.
- (c) A forecaster says there’s a chance of sun today. Find the probability that it is sunny in days’ time.
Solution.
(a) On a GDC (or by multiplying by ):
(b) Start in S (column ) and end in R (row ): .
(c) , so
The probability that it is sunny in days is .
Example 3: The steady state
Section titled “Example 3: The steady state”For the weather model, find the long-term proportion of sunny days
- (a) by repeated multiplication
- (b) exactly, by solving a system of equations.
Solution.
(a) All entries of are already positive, so the chain is regular. A GDC gives
Both columns are the same, so whatever the weather today, in the long run about of days are sunny.
(b) Let with :
Both equations simplify to , that is, . (For a transition matrix the two equations always say the same thing, which is why you need the extra condition.) Now use :
In the long run, of days are sunny. Check: . ✓
Example 4: Brand switching
Section titled “Example 4: Brand switching”A town has three phone companies, A, B and C. Each year:
- A keeps of its customers, loses to B and to C
- B keeps , loses to A and to C
- C keeps , loses to A and to B.
This year, the market shares are A , B , C , and there are customers in total.
- (a) Write the transition matrix.
- (b) Find the market shares in years.
- (c) Find the long-term number of customers of each company.
Solution.
(a) Each column is a “from” company (order A, B, C):
Check: each column adds to .
(b) , and a GDC gives
In years: A , B , C (to 3 s.f.).
(c) Every entry of is positive, so the chain is regular and has a steady state . From , the first two equations are
Replace the third with and solve the system on a GDC:
(Repeated multiplication agrees: every column of is to 3 s.f.)
Long-term customers, using the exact fractions:
(to the nearest customer; check: ).
Common mistakes
Section titled “Common mistakes”Putting the probabilities in rows instead of columns. In the IB convention, is the probability of going from to , so each column adds to . If your rows add to and your columns don’t, you’ve built the transpose.
Multiplying in the wrong order. It’s , with the state matrix on the right. isn’t even defined for a column vector .
Computing T to the power n incorrectly. means as matrices, not cubing each entry. Use your GDC’s matrix power.
Forgetting the “adds to 1” equation. The equations from alone always have infinitely many solutions (any multiple of works). You need (or ) to pin down the steady state.
Assuming every chain has a steady state that ignores the start. That’s guaranteed for regular chains. Check that some power of has all entries positive.
Giving long-term numbers as unrounded decimals. If the state matrix counts people or objects, round the final answers sensibly (like customers) and check that they add to the total.
Practice
Section titled “Practice”1. (Warm-up) Using the IB column convention, which of these could be transition matrices? Explain.
Solution
: yes. All entries are between and , and each column adds to (, ).
: no. Its columns add to and . (Its rows add to , so it would be a transition matrix in the other, row convention; its transpose is a valid IB transition matrix.)
: no. Entries are probabilities, so they can’t be negative or greater than .
2. (Warm-up) If Ana goes to the gym one day, the probability that she goes the next day is . If she doesn’t go one day, the probability that she goes the next day is . Today there’s a chance she goes.
- (a) Write the transition matrix, with states in the order “gym”, “no gym”.
- (b) Find the probability that she goes to the gym tomorrow.
Solution
(a)
(b)
The probability is .
3. (Core) A student travels to school by bus (B), bicycle (C) or car (D). Each day:
- after taking the bus, she takes the bus again with probability , cycles with probability , and goes by car with probability
- after cycling, she takes the bus with probability , cycles with probability , and goes by car with probability
- after going by car, she takes the bus with probability , cycles with probability , and goes by car with probability .
She cycled today. Find the probability of each way of travelling in days’ time.
Solution
With states in the order B, C, D:
is the second column of : . Then
Bus , bicycle , car . (Check: .)
4. (Core) For the weather model (order sunny, rainy), it is rainy today. Find the probability that it is sunny in days’ time.
Solution
On a GDC:
Start in R (column ), end in S (row ): (to 3 s.f.).
Notice that this is already close to the long-term value from Example 3.
5. (Core) A Markov chain has transition matrix . Find the exact steady-state matrix.
Solution
Let . From the first row of :
With : , so and .
Check: ✓ and ✓.
6. (Core) A bike-share scheme has bikes at three stations, X, Y and Z. Each day, the bikes move according to
(order X, Y, Z; for example, of the bikes at X end the day at Y).
- (a) There are bikes at each station this morning. How many will be at each station tomorrow morning?
- (b) In the long run, about how many bikes will be at each station?
Solution
(a)
X: , Y: , Z: .
(b) Every entry of is positive, so the chain is regular. Solve with :
A GDC gives , , . Multiplying by : X , Y , Z .
In the long run there will be about bikes at X, at Y and at Z.
7. (Core) Decide whether each transition matrix is regular. Explain.
Solution
: regular. has all entries positive.
: not regular. Once the chain is in state it never leaves (column is ), so the bottom-left entry of every power is . For example, .
: not regular. The chain moves around the cycle with certainty. Its powers are , , , and so on, and each of these has zeros.
8. (Challenge) A two-state Markov chain has transition matrix , where . Its steady state is . Find .
Solution
The steady state satisfies . The first row gives
Check with the second row: . ✓
9. (Challenge) For the weather model :
- (a) Find the eigenvalues of .
- (b) Show that is an eigenvector for the eigenvalue , and explain how it gives the steady state.
- (c) Use the other eigenvalue to explain why the columns of get close to the steady state quickly.
Solution
(a) Solve :
So or .
(b)
so it is an eigenvector with eigenvalue . Any multiple of it satisfies ; scaling so the entries add to (divide by ) gives the steady state , as in Example 3.
(c) Any initial state can be written as the steady state plus a multiple of the eigenvector for . Each step multiplies that second part by , so after steps it has been multiplied by , which shrinks to fast (for example, ). What’s left is the steady state. That’s why in question 4 was already within about of .