function err = r8mat_eigenvalues_positive ( A )

%*****************************************************************************80
%
%% r8mat_eigenvalues_positive() checks a real matrix for positive eigenvalues.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    25 September 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real A(M,N), the matrix.
%
%  Output:
%
%    real ERR: if positive, all eigenvalues are positive and the smallest is E.
%              if zero or negative, at least one eigenvalue is zero, negative,
%              or complex.
%
  [ m, n ] = size ( A );
  
  if ( m ~= n )
    err = realmax ( );
    return
  end

  e = eig ( A );

  if ( any ( imag ( e ) ~= 0.0 & real ( e ) <= 0.0 ) )
    i = find ( imag ( e ) ~= 0.0 & real ( e ) <= 0.0 );
    err = - max ( abs ( e(i) ) );
    return
  end

  if ( any ( imag ( e ) ~= 0.0 & 0.0 < real ( e ) ) )
    i = find ( imag ( e ) ~= 0.0 & 0.0 < real ( e ) );
    err = - max ( abs ( imag ( e(i) ) ) );
    return
  end

  err = min ( e );

  return
end
