Andof course S0*T^i will never equal S0*T^(i-1) - the exponent is different! What you need to do is use i and (i-1) asindexes into the S0 array. It looks like S0 better be an array or you won't get it to work.
function stationarystates(S0,T) %This function is a simple model of a Markov chain % S0 is the initial state % T is the transition matrix % I want the cumulation of states to stop after state i if the difference % between states is small enough.
m1 = S0*T^i;
m2 = S0*T^(i-1);
mDiff = abs(m2-m1);
if max(mDiff(:)) > 0.00001; % The states are essentially equal.