%compute page ranks for graphs

%link matrix

A(1:7,1:7)=0;
A(1,2)=1;
A(2,1)=1;
A(2,3)=1/3;
A(2,4)=1/2;
A(4,3)=1/3;
A(4,5)=1;
A(5,4)=1/2;
A(5,3)=1/3;
A(6,7)=1;
A(7,6)=1;

%probability for jump to random site rather than specific link
eps=0.15;

%right hand side

r=eps/7*ones(7,1);

%construct matrix with diffusion and subtract identity
S=((1-eps)*A-eye(7));

%compute pagerank
pr=-S\r


% site #7 adds two paid-for link from 'bad' websites 4 and 5
A(7,4)=1/3;
A(7,5)=1/2;
%of course, the other links from 4 and 5 need to be downgraded to less likely
A(2,4)=1/3;
A(4,5)=1/2;

%compute corrupted page rank
Scorrupt=((1-eps)*A-eye(7));


prcorrupt=-Scorrupt\r

