% tinyWeb.m
% Example of a tiny web from Moler: chap. 2

clear all; bigscreen;
n = 6;
p = 0.85;
i = [2 3 4 4 5 6 1 6 1]; 
j = [1 2 2 3 3 3 4 5 6]; 

G = sparse(i,j,1,n,n);
full(G)
c = full(sum(G))
D = spdiags(1./c',0,n,n);
I = speye(n);
% e = ones(n,1);
% delta = (1-p)/n;
% x = (I-p*G*D)\(delta*e)
% Faster if the above 3 lines are replaced by the following 3 lines.
delta = (1-p)/n;
deltae = repmat(delta,n,1); % n x 1 vector whose elements are all given by delta
x = (I-p*G*D)\(deltae)

bar(x); ylabel('PageRank','fontSize',24);
title('Example of a Tiny Web','fontSize',24)
set(gca,'fontSize',20); axis([0.2 6.8 0 0.35]);