% Web Page Ranking Demonstration
%
% Prepared by: Douglas Meade
%              22 August 2005

rhoC = 0.85;      % Prob(click to next page)=0.85
C=[0 1 1 1;       % Connectivity matrix
   1 0 1 0;
   1 0 0 0;
   0 1 1 0];

Csum = sum(C);    % Normalize columns of connectivity matrix so that:
CsumR = 1./Csum;  %    Cstar(i,j)=Prob(click from page j to page i)
Cstar = [CsumR;CsumR;CsumR;CsumR].*C;

rhoT = 0.15;      % Prob(type to next page)=0.15
T=ones(4,4);      % Connectivity matrix for typing URLs (all pages connected)
Tsum = sum(T);    % Normalize columns of connectivity matrix so that:
TsumR = 1./Tsum;  %    Tstar(i,j)=Prob(type from page j to page 1)
Tstar = [TsumR;TsumR;TsumR;TsumR].*T

A = rhoT*Tstar + rhoC*Cstar

%A = [ 3/80 37/80 77/240 71/80;
%   37/80 3/80 77/240  3/80;
%   37/80 3/80  3/80  3/80;
%   3/80 37/80 77/240 3/80 ];


% Eigenvalue Computation
[V,D]=eig(A)
v = V(:,1);
xstar = v/sum(v)

% Iteration to Steady-State
x0 = [1;0;0;0];  % initial distribution of web users

x = x0;
R = x0;
for t = 1:30,
   y = A*x;
   x = y/sum(y);
   R = [R,x];
end;
R

