Page Rank Matlab Code

Matlab code of the original Google Page rank algorithm is given below.� Using this Matlab code, you can simply put rotated adjacency matrix of any directed network graph as input. That is

L =rot90(rot90( A ))

Similarly, we can say

A =rot90(rot90( L ))

The code can run without any input because the input example and parameter are given exactly as explained in the example of this tutorial. The basic computation in this code is based on recursive Page Rank formula .

function p=PageRank(L,d)
% return PageRank vector
%
% input:
% d = constant parameter
%
% Example from Kardi Teknomo's Page Rank tutorial
% is given as input and output of this function.
% Read the full tutorial for more explanation.
%
% (c) 2012 Kardi Teknomo
% http://people.revoledu.com/kardi/tutorial/
%%%%%%%%%%%%%%%%%%%%%%%

if nargin<1
L=[1 1 1 1 1 1;
0 1 1 1 1 1;
0 0 1 1 1 1;
0 0 0 1 1 1;
0 0 0 0 1 1;
0 0 0 0 0 1;];
end
if nargin<2,
d=0.85;
end

[m,n]=size(L);
c=sum(L);
L_c=L./ repmat (c,m,1);
k=0;

while 1
k=k+1;
for i=1:m
p(i)=(1-d)+d*(L_c(i,:)*c');
end
c=p;
if sum(sum(p))==m || k>256,
break;
end
end

Variable k represent the number of iteration and we set limit the loop up to 256 iterations. If you run the code above, it will produce row vector p = [4.3254��� 0.6488��� 0.3731��� 0.2674��� 0.2106��� 0.1748].

In the next section, we will encourage you to use the Page Rank tool to compare the Page Rank