function r8ge_sl_it_test ( )

%*****************************************************************************80
%
%% r8ge_sl_it_test() tests r8ge_sl_it().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  n = 6;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'r8ge_sl_it_test():\n' );
  fprintf ( 1, '  r8ge_sl_it() applies one step of iterative \n' );
  fprintf ( 1, '  refinement to a R8GE_SL solution.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Matrix order N = %d\n', n );
%
%  Set the coefficient matrix.
%
  a = r8ge_hilbert_inverse ( n );
%
%  Set the right hand side b.
%
  b(1:n-1) = 0.0E+00;
  b(n) = 1.0E+00;
%
%  Compute the factored coefficient matrix.
%
  [ a_lu, pivot, info ] = r8ge_fa ( n, a );

  if ( info ~= 0 ) then
    fprintf ( 1, '\n' );
    fprintf ( 1, 'R8GE_SL_IT_TEST - Fatal error!\n' );
    fprintf ( 1, '  R8GE_FA declares the matrix is singular!\n' );
    fprintf ( 1, '  The value of INFO is %d\n', info );
    return
  end
%
%  Solve the system.
%  (Careful!  R8GE_SL overwrites the right hand side with the solution!)
%
  job = 1;
  x = r8ge_sl ( n, a_lu, pivot, b, job );
%
%  Compute and print the residual.
%
  r = r8ge_res ( n, n, a, x, b );

  r8vec2_print_some ( n, x, r, 10, '  i, x, b-A*x' );
%
%  Take a few steps of iterative refinement.
%
  for j = 1 : 5

    fprintf ( 1, '\n' );
    fprintf ( 1, 'Iterative refinement step %d\n', j );
    fprintf ( 1, '\n' );
%
%  Improve the solution.
%
    [ x_new, r ] = r8ge_sl_it ( n, a, a_lu, pivot, b, job, x );

    r8vec_print_some ( n, r, 10, '  I, DX:' );
%
%  Compute and print the residual.
%
    r = r8ge_res ( n, n, a, x_new, b );

    r8vec2_print_some ( n, x_new, r, 10, '  i, x, b-A*x' );

    x(1:n) = x_new(1:n);

  end

  return
end
