Mathematics · Simulator 053
Tomorrow's weather depends only on today's: that's a Markov chain. Edit the transition probabilities between sunny, cloudy and rainy days, watch a random walk hop between states, and see the long-run share of each state settle onto the stationary distribution.
CollegeCollege probability
A Markov chain has states and a transition matrix P, where Pᵢⱼ is the probability of moving from state i to state j in one step. Each row sums to 1. The future depends only on the present state, not the history (the Markov property).
The distribution after n steps is π₀Pⁿ. For a chain where every state can reach every other and there is no fixed cycle, this converges to a unique stationary distribution π with πP = π, whatever the starting state. The simulator finds π by repeatedly applying P.
The bars compare the fraction of days spent in each state so far with π. They agree better and better as the walk gets longer (the ergodic theorem). Mean return time to a state is 1/πᵢ.
Illustrative weather model with editable probabilities, not real climate data. Rows are normalised automatically if they do not sum to 1.
For a two-state chain with P(sun → rain) = 0.2 and P(rain → sun) = 0.4, what fraction of days are rainy in the long run?
Balance requires π_sun × 0.2 = π_rain × 0.4, so π_rain = π_sun / 2. Together they sum to 1, so π_rain = 1/3. Set cloudy transitions to 0 to reproduce it.
Default weather chain (rows are today, columns tomorrow): Sunny 0.6 / 0.3 / 0.1, Cloudy 0.3 / 0.4 / 0.3, Rainy 0.2 / 0.4 / 0.4.
Two days ahead: from a sunny day, P(rain in two days) = 0.6 × 0.1 + 0.3 × 0.3 + 0.1 × 0.4 = 0.19.
Long-run shares: solve π = πP with the shares adding to 1. The balance equations give Cloudy = 11/12 × Sunny and Rainy = 5/8 × Sunny, so π = (24, 22, 15) / 61 ≈ 39% sunny, 36% cloudy, 25% rainy.
Rainy spells: rain stays rain with probability 0.4, so a spell lasts on average 1 / (1 − 0.4) ≈ 1.7 days. With the sticky setting (0.9) it lasts 10 days.
Load the default chain, run 1000 days and compare the visit shares with 39%, 36% and 25%.
A random process where the next state depends only on the current state, not on how it got there. It is described by a table of transition probabilities whose rows each add to 1.
The long-run share of time spent in each state. Once the chain is in it, one more step leaves it unchanged: π = πP.
Not always. A chain that is split into separate parts, or that cycles with a fixed period, may never settle. Chains where every state can reach every other and there is no fixed rhythm always converge to one stationary distribution.