Shailrshah

PageRank

Apr 4th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.39 KB | None | 0 0
  1. n = 3;
  2. m = [1/2 1/2 0; 1/2 0 0; 0 1/2 1];
  3. beta = 0.8;
  4. e = ones(3, 1);
  5. v0 = e/n;
  6. while true
  7.     next = beta*m*v0+(1-beta)*e/n;
  8.     if next==v0
  9.         disp(sprintf('PageRank computed in %d steps. \npr(A)=%f\tpr(B)=%f\tpr(C)=%f', i, v0(1), v0(2), v0(3)));
  10.         break
  11.     else
  12.         v0=next;
  13.     end
  14. end
  15.  
  16. %PageRank computed in 87 steps.
  17. %pr(A)=0.212121 pr(B)=0.151515  pr(C)=0.636364
Add Comment
Please, Sign In to add comment