function det = p_det ( P )
%
%  function det = p_det ( P )
%
%  P_DET returns the determinant of a permutation matrix.
%
%  Discussion:
%
%    A permutation matrix is a square matrix with a single 1.0 in each 
%    row and column, with all other entries being zero.
%
%    The determinant of a permutation matrix is -1 raised to the
%    power of the number of pairwise interchanges that are equivalent
%    to the permutation.
%
%  Modified:
%
%    15 February 2000
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real P(N,N), the permutation matrix.  
%
%    Output, real DET, the determinant of the permutation matrix.
%    +1, the permutation is even,
%    -1, the permutation is odd.
%
  [ n, n ] = size ( P );

  det = 1.0;

  for k = 1 : n-1
%
%  Seek the maximum entry in column K (presumably, the "1").
%
    [ colmax, i ] = max ( abs ( P(:, k ) ) );
%
%  If the maximum entry is not in row K, then we want to
%  switch rows I and K, and change the sign of the determinant.
%
    if i ~= k
      det = - det;
      P( [k,i], : ) = P( [i,k], : );
    end

  end
%
%  At this point, P should actually be restored to the identity matrix.
%  For now, we'll simply trust that this is true.
%
