Markov Chain Steady-State Calculator
Stationary Distribution · Gaussian Elimination · Power Iteration
Enter an n×n transition probability matrix to find the steady-state distribution πP = π via Gaussian elimination. Includes power iteration convergence and bar chart.
Quick Examples
Steady-State Verification (πP = π)
Steady-State Distribution Chart
Power Iteration Convergence
πk = π0 × Pk starting from uniform distribution. Shows convergence at k = 1, 2, 5, 10, 20, 50.
Run the calculator first.
Gaussian Elimination — Augmented Matrix Steps
Solving (PT − I)π = 0, last equation replaced by Σπᵢ = 1.
Run the calculator first.
What Is a Markov Chain?
A Markov chain is a stochastic process that transitions between a finite set of states according to fixed transition probabilities, with the crucial property that the next state depends only on the current state — not on any prior history. This memoryless property, known as the Markov property, makes these models both mathematically tractable and practically powerful.
Formally, a discrete-time Markov chain is defined by a transition probability matrix P, where each entry P[i][j] gives the probability of moving from state i to state j in one step. Every row of P must sum to exactly 1.0, making P a row-stochastic matrix. Starting from any initial distribution π0, the distribution after k steps is πk = π0 × Pk.
The Steady-State (Stationary) Distribution
The steady-state distribution π = [π1, π2, …, πn] is a probability vector satisfying two conditions:
- Balance equation: πP = π — the distribution is unchanged by one step of the chain
- Normalization: Σπi = 1 — the values form a valid probability distribution
Intuitively, πi is the long-run fraction of time the chain spends in state i. For ergodic chains (irreducible and aperiodic), the distribution Pkij converges to πj as k → ∞, regardless of the starting state.
When Does a Unique Steady State Exist?
A unique stationary distribution is guaranteed for ergodic Markov chains:
- Irreducible: Every state can reach every other state (the chain cannot get permanently trapped in a subset)
- Aperiodic: No state has a forced periodic cycle (the GCD of return times is 1)
The Perron-Frobenius theorem guarantees that a positive stochastic matrix always has a unique stationary distribution — this is the theoretical foundation underpinning PageRank and many other applications.
Solution Methods
Gaussian Elimination
Rewrite πP = π as (PT − I)π = 0. This is a homogeneous linear system, which has infinitely many solutions (all scalar multiples of the stationary vector). To obtain a unique solution, we replace the last equation with the normalization constraint Σπi = 1 and apply Gaussian elimination with partial pivoting for numerical stability.
Power Iteration
Start with a uniform distribution π0 = [1/n, 1/n, …, 1/n] and iterate πk+1 = πkP until convergence. The rate of convergence is governed by the second-largest eigenvalue |λ2| of P: convergence is fast when this is small, and slow (or absent) for nearly-periodic chains.
Mean Recurrence Time
For ergodic chains, the mean recurrence time μi = 1/πi gives the expected number of steps between successive visits to state i. States with high steady-state probability have short recurrence times, and vice versa. This quantity is directly used in the analysis of random walks, search algorithms, and mixing times.
Real-World Applications
- PageRank: Google models the web as a Markov chain; the steady-state distribution ranks pages by importance
- Finance: Credit rating agencies model transitions between AAA, AA, A, …, Default ratings as a Markov chain to estimate long-run default probabilities
- Genetics: Hardy-Weinberg equilibrium and allele frequency drift under mutation can be modeled as Markov chains
- Weather modeling: Simplified climate patterns (Sunny/Cloudy/Rainy) captured as transition matrices
- Queueing theory: Server load and queue lengths in steady state are computed from the stationary distribution of M/M/1 and related chains
- NLP: Text generation, spell correction, and speech recognition all use Markov models; language models are higher-order Markov chains
Reference: Weather Example (2×2)
| From / To | Sunny | Rainy |
|---|---|---|
| Sunny | 0.8 | 0.2 |
| Rainy | 0.4 | 0.6 |
Steady state: π = [2/3, 1/3] ≈ [0.6667, 0.3333]. Long-run 66.7% of days are sunny, 33.3% rainy, regardless of today's weather.