function a_det = rref_determinant ( A )

%*****************************************************************************80
%
%% rref_determinant() uses reduced row echelon form (RREF) to compute a determinant.
%
%  Discussion:
%
%    The procedure will fail if A is not square.
%
%    This is simply a demonstration of how the RREF can be used to compute
%    the determinant.  There are better ways to compute the inverse, 
%    including Octave's d = det ( A )
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 December 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real A(N,N), a square matrix.
%
%  Output:
%
%    real A_DET: the determinant.
%
  [ m, n ] = size ( A );

  if ( m ~= n )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'rref_determinant(): Fatal error!\n' );
    fprintf ( 1, '  Input matrix is not square.\n' );
    error ( 'rref_determinant(): Fatal error!\n' );
  end
%
%  Do an RREF on A.
%
  [ ARREF, a_cols ] = rref_compute ( A );
%
%  Compute product of diagonal entries.
%
  a_det = 1.0;
  for i = 1 : n
    a_det = a_det * ARREF(i,i);
  end

  return
end

