function i4mat_rref_system_test ( )

%*****************************************************************************80
%
%% i4mat_rref_system_test() tests i4mat_rref_system().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 September 2018
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'i4mat_rref_system_test():\n' );
  fprintf ( 1, '  i4mat_rref_system() computes the linear system associated\n' );
  fprintf ( 1, '  with an integer reduced row echelon form of an I4MAT.\n' );
%
%  "Wide" matrix.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Look at a "wide" matrix:\n' );

  m = 4;
  n = 7;

  a1 = [ ...
    1,  3, 0,  2,  6, 3, 1; ...
   -2, -6, 0, -2, -8, 3, 1; ...
    3,  9, 0,  0,  6, 6, 2; ...
   -1, -3, 0,  1,  0, 9, 3 ];

  i4mat_print ( m, n, a1, '  Input A1:' );

  [ a2, det ] = i4mat_rref ( m, n, a1 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The pseudo-determinant = %d\n', det );

  i4mat_print ( m, n, a2, '  A2, the IRREF of A1:' );

  b2 = [ 1; 1; 1; 0 ];
  i4vec_print ( m, b2, '  B2, the right hand side:' );

  [ a3, b3, incon, freedom_num, freedom ] = i4mat_rref_system ( m, n, a2, b2 );

  fprintf ( 1, '\n' );
  if ( incon )
    fprintf ( 1, '  The original system is INCONSISTENT.\n' );
  else
    fprintf ( 1, '  The original system is CONSISTENT.\n' );
  end

  i4mat_print ( n, n, a3, '  A3, the augmented IRREF:' );
  i4vec_print ( n, b3, '  B3, the augmented RHS:' );
  i4vec_print ( freedom_num, freedom, '  Indices of degrees of freedom.' );
%
%  "Tall" matrix.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Look at a "tall" matrix:\n' );

  m = 7;
  n = 4;

  a1 = [ ...
    1, -2, 3, -1; ...
    3, -6, 9, -3; ...
    0,  0, 0,  0; ...
    2, -2, 0,  1; ...
    6, -8, 6,  0; ...
    3,  3, 6,  9; ...
    1,  1, 2,  3 ];

  i4mat_print ( m, n, a1, '  Input A1:' );

  [ a2, det ] = i4mat_rref ( m, n, a1 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The pseudo-determinant = %d\n', det );

  i4mat_print ( m, n, a2, '  A2, the IRREF of A1:' );

  b2 = ones ( m, 1 );
  i4vec_print ( m, b2, '  B2, the right hand side:' );

  [ a3, b3, incon, freedom_num, freedom ] = i4mat_rref_system ( m, n, a2, b2 );

  fprintf ( 1, '\n' );
  if ( incon )
    fprintf ( 1, '  The original system is INCONSISTENT.\n' );
  else
    fprintf ( 1, '  The original system is CONSISTENT.\n' );
  end

  i4mat_print ( n, n, a3, '  A3, the augmented IRREF:' );
  i4vec_print ( n, b3, '  B3, the augmented RHS:' );
  i4vec_print ( freedom_num, freedom, '  Indices of degrees of freedom.' );

  return
end
