function medium_page2_test ( )

%*****************************************************************************80
%
%% medium_page2_test carries out the page2 algorithm for the "medium" dataset.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'medium_page2_test:\n' );
  fprintf ( 1, '  Pagerank algorithm #2 for the "medium" dataset.\n' );
%
%  Read the adjacency matrix from the sparse matrix file.
%
  data = load ( 'medium_sparse.txt' );
  A = spconvert ( data );
  nonzeros = nnz ( A );
  A = full ( A );
  [ m, n ] = size ( A );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of nodes = %d\n', n );  
  fprintf ( 1, '  Number of nonzero elements = %d\n', nonzeros );
%
%  Copy T = A'
%  Then normalize each nonzero column of T to have sum 1.
%
  T = A';

  for j = 1 : n
    if ( 0.0 < sum ( T(:,j) ) )
      T(:,j) = T(:,j) / sum ( T(:,j) );
    else
      T(:,j) = 1.0 / n;
    end
  end
%
%  G = (1-p)/n + p * T
%
  p = 0.85;

  G = (1-p)/n * ones(n,n) + p * T;
%
%  Solve G*x = x.
%  x is the eigenvector corresponding to eigenvalue 1.
%  1 is the maximal eigenvalue.
%  eigs will return in column 1 of V the eigenvector corresponding to 
%  the largest eigenvalue.
%
  [ V, D ] = eigs ( G );

  ranking = abs ( V(:,1) ) / norm ( V(:,1), 1 );
  label = 1 : n;
  r8vec2_print ( label, ranking, '  Page2 rankings:' );

  return
end
