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.
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.