function [x,reshist] = pr_rich(P,alpha,v,tol,maxiter)
% PR_RICH Compute PageRank via the Richardson method

x = (1-alpha)*v;
reshist = zeros(maxiter,1);
t0 = tic;

for iter=1:maxiter
    y = P'*x;
    y = alpha*y;
    w = norm(y,1);
    y = y + (1-w)*v;
    x = x - y;
    reshist(iter) = norm(x,1);
    x = y; 
    fprintf('iter = %i  residual = %8.2e  dt=%7.1f\n', iter, reshist(iter), toc(t0));
    if reshist(iter) < tol, break; end
end
reshist = reshist(1:iter);
if reshist(end) > tol, warning('did not converge'); end