%% Math 152: Random walk demo
% Example from lectures with a 3-state walker.

%% transition matrix

P = [0   1/3 1/4;
     1/2 0   3/4;
     1/2 2/3 0]

%% initial state

x0 = [1; 0; 0]

%% after one and two steps

x1 = P*x0
x2 = P*x1
x2 = P^2*x0   % equivalent

%% long-term behaviour
x = x0
for n=1:40
  x = P*x
end

%% alternatively:
x = P^10*x0
x = P^20*x0
x = P^40*x0

%% explore different initial states
x0 = [1; 1; 1]/3

x = P^50*x0
