Below are two examples of the PageRank algorithm on small networks.

AMS example :

The sample network here comes from an article by David Austin :
   http://www.ams.org/samplings/feature-column/fcarc-pagerank
The image of the network I want to discuss is a bit over halfway down the page, or at
   http://www.ams.org/featurecolumn/images/december2006/reducible.jpg

T={
{0,0,0,0,0,0,0,0},
{1/2,0,1/2,1/3,0,0,0,0},
{1/2,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,0,1/2,1/3,0,0,1/2,0},
{0,0,0,1/3,1/3,0,0,1/2},
{0,0,0,0,1/3,0,0,1/2},
{0,0,0,0,1/3,1,1/2,0}};
MatrixForm[T]

Here we' ll just let Mathematica find the eigenvalues and eigenvectors for us:

{eVals, eVecs} = Eigensystem[T];
MatrixForm[eVals]

Eigenvalue 1 only appears once, so this system has a unique (up to scalar multiple) stable state, namely:

MatrixForm[1.0eVecs[[1]]]

(or, rescaled :

MatrixForm[eVecs[[1]]/(eVecs[[1]] . {1,1,1,1,1,1,1,1})]

Whoa!  This only ranks the last four sites, and says the first four are unimportant!  This is because the last four sites act together as a "sink"; although there isn’t one single site with no outgoing links, these four together have no links going to the rest.
This can happen in practice, but we really want to rank everybody.  Those first four sites should be comparable.
(Maybe our final ranking will have a few sites with equal values, but if we don’t fix this zero issue we might end up with most sites incomparable!)
This is another reason to insist on strictly positive entries.  Then the eigenvector will also have strictly positive entries.
And besides, this interpretation makes sense: if you get stuck in a set of four sites which only link to each other, eventually you’ll just back out and pick a new site at random.

newT = 0.85 T + 0.15/8;
MatrixForm[newT]

(Note: Mathematica allows you to add a constant to every entry of a matrix by the above notation; in better mathematical notation, I should add 0.15(Subscript[S, n]), where (Subscript[S, n]) was defined in class as the matrix with every entry equal to 1/n.)

{neweVals, neweVecs} = Eigensystem[newT];
MatrixForm[neweVals]

Again we' ve got the eigenvalue 1 with just multiplicity 1; and again we’ll use the eigenvector methods from class here.

stablevec=neweVecs[[1]];
MatrixForm[stablevec]

This is good enough for a ranking.  But we can force the sum of the entries to be 1, to satisfy our interpretation as a probability space :

MatrixForm[stablevec/(stablevec . {1,1,1,1,1,1,1,1})]

And now we can check (if we like) that this is also what we get in the limit :

MatrixForm[MatrixPower[newT, 1000, {1/8,1/8,1/8,1/8,1/8,1/8,1/8,1/8}]]

or another initial configuration (everybody starts at site 1) :

MatrixForm[MatrixPower[newT, 1000, {1,0,0,0,0,0,0,0}]]

Prep Problem example :

Here' s the transition matrix corresponding to the diagram in the practice problem (check that!).

T={
{0,0,0,1,1,0},
{1/2,0,0,0,0,0},
{0,1/2,0,0,0,0},
{0,1/2,1/3,0,0,0},
{1/2,0,1/3,0,0,0},
{0,0,1/3,0,0,0}};
MatrixForm[T]

And here's (an approximation of) the limit  of (T^k)v, for the initial configuration v putting an equal number of surfers at each webpage:

MatrixForm[MatrixPower[T,1000,1/6{1.0,1,1,1,1,1}]]

That' s the zero vector (approximately)!  What went wrong?
Our matrix T has a zero column for website F.  So any surfer on page F disappears!  To fix this, we can just send any surfer on page F to a random page:

S=T+{{0,0,0,0,0,1/6},{0,0,0,0,0,1/6},{0,0,0,0,0,1/6},{0,0,0,0,0,1/6},{0,0,0,0,0,1/6},{0,0,0,0,0,1/6}};
MatrixForm[S]

MatrixForm[MatrixPower[S,1000,1/6{1.0,1,1,1,1,1}]]

Now that' s more like it.  It looks like we got lucky and the steady state exists.  (Although there could be problems, like we discussed briefly in discussion: there could be other steady states depending on the initial conditions.)  Let’s fix this by making the matrix have all strictly positive entries; then (recall) there will be a unique steady state, which will be the limit of the situation for any initial configuration.

R=0.85 S + 0.15/6;
MatrixForm[R]

MatrixForm[MatrixPower[R,1000,1/6{1.0,1,1,1,1,1}]]

There' s our final PageRank: sites rank in decreasing order of “importance” AEBDCF.