Markov Chain Calculator
Transition matrix editor with a state diagram, distribution after n steps and its chart, steady state with working, absorbing-chain analysis and a random-walk simulation.
S'executa al teu navegador. Els fitxers mai no surten del dispositiu. Mira com comprovar-ho
…
Com es fa
- 1Load or size the chain
Choose an example or set the number of states and name them.
- 2Fill in the matrix
Type each probability so every row adds up to 1, and set the starting distribution.
- 3Choose n
Enter the number of steps and read the distribution, the chart and the matrix Pⁿ.
- 4Find the long run
Open Long run for the steady state with working or the absorbing-chain results.
- 5Simulate
Run a random walk and compare time shares with the steady state.
- 6Save and practise
Save chains, export the distribution CSV and diagram PNG, or practise in Practice.
Sobre aquesta eina
A Markov chain describes something that moves between states, where the chance of the next move depends only on where it is now. Weather, customers switching brands, students moving through year groups and board-game positions can all be modelled this way, and the topic appears in further maths, statistics and operations research courses. Everything follows from the transition matrix P, whose row i lists the probabilities of moving from state i to each state. This calculator lets you build P for up to eight states, checks every row adds up to 1, and draws the state diagram. It then shows the distribution after each step, the long-run steady state with the equations written out, and, for chains with absorbing states, the expected time to absorption and the probability of ending in each absorbing state.
The transition matrix and n steps
Each row of P must contain probabilities that add up to exactly 1. Fractions such as 1/3 are accepted, and a button rescales rows that do not add up. If π₀ is the starting distribution written as a row vector, the distribution after one step is π₁ = π₀P, after two steps π₂ = π₁P = π₀P², and after n steps π₀Pⁿ. The tool lists the first few steps, plots every state's probability up to the chosen n and shows the matrix Pⁿ, whose entry (i, j) is the chance of being in state j n steps after starting in i.
Steady state
For a regular chain, one where some power of P has no zero entries, the distribution settles to a unique steady state π with πP = π and the entries adding to 1. The tool writes those equations out, replaces one redundant equation by the sum condition and solves by elimination. It also reports whether the chain is irreducible (every state can reach every other) and its period. A chain that alternates between two states never settles, but its steady state still gives the long-run share of time in each state.
Absorbing chains
A state is absorbing if P(i, i) = 1, so once entered it is never left. Ordering the states as transient then absorbing splits P into Q (transient to transient) and R (transient to absorbing). The fundamental matrix N = (I − Q)⁻¹ gives the expected number of visits to each transient state, t = N·1 the expected number of steps before absorption, and B = N·R the probability of ending in each absorbing state. The gambler's ruin and student progress examples use this.
Simulation
The Simulate tab runs 40 random steps using the matrix and compares the share of time spent in each state with the steady state, which shows how a single run wanders while the long-run averages settle.
Worked example
Weather: a sunny day is followed by sun with probability 0.9 and rain 0.1; a rainy day by sun 0.5 and rain 0.5. The steady-state equations are π(S) = 0.9π(S) + 0.5π(R) and π(S) + π(R) = 1, giving π(S) = 5/6 ≈ 0.833 and π(R) = 1/6. Starting from a sunny day, the chance of sun two days later is 0.9 × 0.9 + 0.1 × 0.5 = 0.86. In the student progress example, a first-year student graduates with probability 5/6 and needs on average about 2.16 years before graduating or leaving.
Limits
The tool handles discrete-time chains with up to eight states and fixed transition probabilities. Continuous-time chains, hidden Markov models and probabilities that change over time are not covered. Real systems rarely follow a Markov chain exactly, so results describe the model, not certain outcomes.
Exemple resolt
Weather chain [[0.9, 0.1], [0.5, 0.5]]: steady state (5/6, 1/6); P(sunny in 2 days | sunny today) = 0.86.
En resum
- Categoria: Matemàtiques i ciència
- S'executa al navegador, sense registre, sense pujar res.
- La informació que introdueixes es queda al dispositiu.
- Disponible en anglès.
- Contingut revisat per última vegada:
- Font oficial: Grinstead and Snell, Introduction to Probability (AMS), chapter 11: Markov chains
Preguntes freqüents
What makes a process a Markov chain?
The probability of the next state depends only on the current state, not on how the process got there. This is called the Markov property.
Why must each row add up to 1?
Row i lists every possible next state from state i, so the probabilities must cover all outcomes exactly once.
Does every chain have a steady state?
Every finite chain has at least one stationary distribution, but the distribution only converges to it from any start when the chain is regular.
What is an absorbing state?
A state that cannot be left, such as being broke in the gambler's ruin or graduating in a student-progress model.
How do I read the matrix Pⁿ?
Row i, column j is the probability of being in state j after n steps when starting in state i.
Can I use fractions?
Yes. Type values like 1/3 in the matrix and the starting row, and results show simple fractions where they exist.
