function [pi,time,numiter]=rank_play(A, pi0, alpha, epsilon, personal)

%% Computes the PageRank vector of the nxn voting matrix A by using 
%%  Power Method 

%% Input: nxn voting matrix A

%% Output:  PageRank = PageRank vector
%%          time = time required to compute PageRank vector
%%          numiter = number of iterations until convergence

[n,p]=size(A);

%% find row-stochastic (except zero rows) matrix H
rowsum=sum(A')';

for i=1:n;
    if rowsum(i,1)==0;
        H(i,:)=0;
    else
        H(i,:)=A(i,:)/rowsum(i,1);
    end %if
end %for

%% get "a", the dangling node vector, where a(i)=1, if node i
%%  is dangling

rowsumvector=ones(1,n)*H';
nonzerorows=find(rowsumvector);
zerorows=setdiff(1:n,nonzerorows); 
l=length(zerorows);
a=[ones(1,n)-rowsumvector];

k=0;
residual=1;
pi=pi0;
tic;

while (residual >= epsilon)
    prevpi=pi;
    k=k+1;
    pi=alpha*pi*H + (alpha*(pi*a')+1-alpha)*((1/n)*personal)
    residual=norm(pi-prevpi,1);

end

numiter=k;
time=toc;