function r8ge_cg_test ( )

%*****************************************************************************80
%
%% r8ge_cg_test() tests r8ge_cg().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    01 February 2016
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'r8ge_cg_test():\n' );
  fprintf ( 1, '  r8ge_cg() applies CG to an R8GE matrix.\n' );
%
%  Set A to the second difference matrix.
%
  n = 10;

  a = r8ge_dif2 ( n, n );
%
%  Choose a random solution.
%
  x1 = rand ( n, 1 );
%
%  Compute the corresponding right hand side.
%
  b = r8ge_mv ( n, n, a, x1 );
%
%  Call the CG routine.
%
  x2 = ones ( n, 1 );
  x3 = r8ge_cg ( n, a, b, x2 );
%
%  Compute the residual.
%
  r = r8ge_res ( n, n, a, x3, b );
  r_norm = norm ( r(1:n) );
%
%  Compute the error.
%
  x1 = x1(:);
  x3 = x3(:);
  e_norm = norm ( x1 - x3 );
%
%  Report.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of variables N = %d\n', n );
  fprintf ( 1, '  Norm of residual |Ax-b| = %g\n', r_norm );
  fprintf ( 1, '  Norm of error |x1-x2| = %g\n', e_norm );

  return
end
