Techniques to understand computer simulations: Markov chain analysis. 
Transient and occupancy distributions for the 1D-RandomWalk model

Luis R. Izquierdo, Segismundo S. Izquierdo, José M. Galán & José I. Santos

Program to calculate the exact probability distribution of the random walker’s position in time-step 100, having started at a random location, in a 1D-RandomWalk model. This program also calculates the occupancy distribution of the 1D-RandomWalk model.

Licence

Copyright (C) 2008 Luis R. Izquierdo, Segismundo S. Izquierdo, José M. Galán & José I. Santos

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301, USA.

Contact information :
Luis R. Izquierdo
University of Burgos, Spain.
e - mail : luis@izquierdo.name

Setting the Environment

Needs["BarCharts`"];
SetDirectory[NotebookDirectory[]];

Parameters

timestep=100;

Creation of the transition matrix

P=Table[RotateRight[PadRight[{1/2,0,1/2},17],i],{i,0,14}];
PrependTo[P,PadRight[{0,1},17]];
AppendTo[P,PadLeft[{1,0},17]];

Transient Distribution

(* initial state *)
x=Table[1/17,{17}];

(* state after the specified number of timesteps *)
(x=x.MatrixPower[P,timestep])//N

exactBarChart=BarChart[x,BaseStyle->14,BarStyle->GrayLevel[0.9],BarEdgeStyle->Directive[Thin,Dashing[{0}]],BarGroupSpacing->0.07]

Export[StringJoin["1DRandomWalk-transientDistribution.png"],exactBarChart,ImageSize->600];

Occupancy Distribution

PT=Transpose[P];
occupancyDist=First[NullSpace[PT-IdentityMatrix[Length[PT]]]];
occupancyDist=Normalize[occupancyDist,Total]