.googlecode.com</span>

i = [ 2 6 3 4 4 5 6 1 1];
j = [ 1 1 2 2 3 3 3 4 6];
n = 6;
G  = sparse(i,j,1,n,n); <span class="comment">% sparse n x n matrix with 1's in specified positions</span>

c = sum(G,1);
k = find(c~=0); <span class="comment">% non zero outdegree</span>
D = sparse(k,k,1./c(k),n,n);
e = ones(n,1);
I = speye(n,n);
p = 0.85;
</pre><h2>Find the stationary distribution<a name="3"></a></h2><pre class="codeinput">pi = normalize((I - p*G*D)\e);
fprintf(<span class="string">'exact pi\n'</span>);  di