function r8sd_res_test ( )

%*****************************************************************************80
%
%% R8SD_RES_TEST tests R8SD_RES.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    16 July 2016
%
%  Author:
%
%    John Burkardt
%
  n = 10;
  ndiag = 2;
  offset = [ 0, 1 ];

  fprintf ( 1, '\n' );
  fprintf ( 1, 'R8SD_RES_TEST\n' );
  fprintf ( 1, '  R8SD_RES computes a residual r=b-A*x\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Matrix order N = %d\n', n );
  fprintf ( 1, '  Number of diagonals is %d\n', ndiag );

  seed = 123456789;
  [ a, seed ] = r8sd_random ( n, ndiag, offset, seed );
%
%  Print the matrix.
%
  r8sd_print ( n, ndiag, offset, a, '  The R8SD matrix:' );

  x = r8vec_indicator1 ( n );

  r8vec_print ( n, x, '  The vector x:' );

  b = r8sd_mv ( n, ndiag, offset, a, x );

  r8vec_print ( n, b, '  The product b=A*x' );
%
%  Make X2, a bad copy of X.
%
  x2 = zeros ( n, 1 );

  for i = 1 : n
    [ e, seed ] = r8_uniform_01 ( seed );
    x2(i) = x(i) + 0.1 * e;
  end

  r8vec_print ( n, x2, '  The defective vector x2:' );
%
%  Compute R = B-A*X2.
%
  r = r8sd_res ( n, ndiag, offset, a, x2, b );
  
  r8vec_print ( n, r, '  Residual r=b-A*x2:' );

  return
end