# Markov Chain Calculator - Steady State & Absorption

> Enter a transition matrix with exact fractions to get the state diagram, n-step matrix Pⁿ, stationary distribution, classification and absorbing-chain results.

- URL: https://qilingtools.com/en/math/markov
- Category: Math Tools (https://qilingtools.com/en/math)
- Tags: [Math](https://qilingtools.com/en/tags/math), [Statistics](https://qilingtools.com/en/tags/statistics), [Algorithms](https://qilingtools.com/en/tags/algorithm)
- Last updated: 2026-10-26
- Price: Free, no sign-up
- Privacy: Runs locally in the browser; files are never uploaded

For stochastic processes courses, probability homework, or modelling queues, weather or web browsing, type in a transition matrix with 2–10 states (rename them as you like). Fractions such as 1/3 and decimals such as 0.25 both work and everything is computed in exact fractions, so the stationary distribution comes out as 5/8 and 5/16 rather than rounded decimals; each row sum is checked live and there’s a one-click normalise. The tool draws the state diagram — arrow width shows probability, colours mark the classes and absorbing states get a double ring — and gives you the n-step matrix Pⁿ and the distribution πₙ = π₀Pⁿ from any starting distribution (exact up to n = 40, floating point beyond), with a chart of how the distribution evolves; the stationary distribution π solving πP = π, Σπ = 1, with mean return times 1/πᵢ, or one stationary distribution per closed class when it isn’t unique; and a classification into communicating classes (strongly connected components), recurrent and transient states, absorbing states and the period of each class, saying whether the chain is irreducible, aperiodic and ergodic. Whenever there are transient states, the absorption analysis gives the fundamental matrix N = (I − Q)⁻¹, the expected number of steps to absorption and its variance, and the probability B = NR of ending up in each recurrent class or absorbing state. Finally, simulate random walks and compare visit frequencies from one long walk, or end states from many walks, against the theory.

## How to use

1. Pick an example or set the number of states, then fill in the transition probabilities (each row adds up to 1)
2. Read the state diagram, classification, stationary distribution and n-step results
3. For absorbing chains check N, the expected steps and absorption probabilities, and run a simulation against the theory

## Features

- Transition matrix editor with fractions and decimals, live row-sum check and normalise
- State diagram with probability-weighted arrows coloured by class
- n-step matrix Pⁿ and π₀Pⁿ with a distribution chart
- Exact stationary distribution and mean return times, per closed class when not unique
- Classification: communicating classes, recurrent / transient, absorbing, period
- Absorbing chains: fundamental matrix N, expected steps and variance, B = NR
- Random walk simulation compared with theory
- Examples: weather, gambler’s ruin, PageRank, mouse in a maze

## FAQ

### What is a stationary distribution, and is it always unique?

A stationary distribution π satisfies πP = π: if you pick the starting state with these probabilities, the probabilities are the same after one step. Every finite Markov chain has at least one. If the chain has a single closed class — for example, if it’s irreducible — it’s unique. With several closed classes (two absorbing states, say) each class has its own stationary distribution and any weighted average of them is stationary too; the tool lists them separately.

### Why doesn’t Pⁿ converge for some chains?

If the chain is periodic — say states alternate between two groups — Pⁿ keeps flipping between two patterns and never settles. Only irreducible, aperiodic (ergodic) chains have every row of Pⁿ converging to the stationary distribution. Even with a period, though, the time average (P + P² + … + Pⁿ)/n still converges to π, so long-run visit frequencies still equal π.

### What is the fundamental matrix N used for?

Split the states into transient and absorbing, and let Q be the transient-to-transient block of the transition matrix. Entry (i, j) of N = (I − Q)⁻¹ is the expected number of visits to transient state j, starting from i, before absorption. Its row sums are the expected number of steps to absorption, and N times R (the transient-to-absorbing block) gives the probability of ending in each absorbing state. In fair gambler’s ruin, starting with $1 you reach $4 with probability 1/4 after 3 bets on average.

### How do I tell recurrent states from transient ones?

A state is recurrent if, starting there, you return with probability 1, and transient if there’s a chance of never coming back. In a finite chain, group states that can reach each other into classes (strongly connected components): states in a closed class, with no way out, are recurrent and all the others are transient. A state that moves to itself with probability 1 is absorbing and forms a closed class on its own.

## Related tools

- [Graphing Calculator](https://qilingtools.com/en/math/graph): Free online function graphing calculator: type sin(x), x^2 or 1/x and see the curve at once, with several functions, parametric and polar curves, PNG export.
- [Scientific Calculator](https://qilingtools.com/en/math/calculator): Free online scientific calculator: type 2*(3+4)^2, sin(pi/6) or log(8,2) and see the answer as you type, with degrees or radians and a history list.
- [Equation Solver](https://qilingtools.com/en/math/equation): Free online equation solver: enter coefficients for linear, quadratic (with discriminant, vertex and complex roots) and cubic equations, plus 2×2 systems.
- [Fraction Calculator](https://qilingtools.com/en/math/fraction): Free online fraction calculator: add, subtract, multiply and divide fractions with automatic reduction, plus fraction ↔ decimal with repeating digits.
- [Percentage Calculator](https://qilingtools.com/en/math/percentage): Free online percentage calculator: X% of Y, X as a percent of Y, increase and decrease, a value after a percentage change and the original behind it.
- [Prime Factorization](https://qilingtools.com/en/math/prime): Free online prime factorization: factor an integer with exponents, list every divisor and their sum, test primality with neighbouring primes, or list a range.
- [GCD and LCM](https://qilingtools.com/en/math/gcd-lcm): Free online GCD and LCM calculator: works with two or more integers, says whether they are coprime, shows each prime factorization and every Euclidean step.
- [Statistics Calculator](https://qilingtools.com/en/math/statistics): Free online statistics calculator: paste a data set for the mean, median, mode, range, quartiles, variance, standard deviation, standard error and outliers.
