function error_frobenius = r8mat_is_normal ( m, n, a )

%*****************************************************************************80
%
%% R8MAT_IS_NORMAL determines whether an R8MAT is normal.
%
%  Discussion:
%
%    An R8MAT is a matrix of real values.
%
%    A real square matrix A is normal if
%
%      A * A' = A' * A.
%
%    A (real) matrix is normal if and only if it is diagonalizable,
%    that is, orthogonally similar to a diagonal matrix:
%
%      A = U' * D * U.
%
%    A matrix is automatically normal if it is symmetric, anti-symmetric,
%    orthogonal, or diagonal.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 April 2017
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, N, the row and column dimensions of 
%    the matrix.  M and N must be positive.
%
%    real A(M,N), the matrix.
%
%  Output:
%
%    real ERROR_FROBENIUS, the Frobenius error, which
%    is zero if the matrix is exactly normal.
%

%
%  If not square, no hope.
%
  if ( ~ r8mat_is_square ( m, n ) )
    error_frobenius = Inf;
    return
  end
%
%  Compare A * A' to A' * A.
%
  error_frobenius = 0.0;

  for i = 1 : m
    for j = 1 : n

      bij = 0.0;
      cij = 0.0;
      for k = 1 : n
        bij = bij + a(i,k) * a(j,k);
        cij = cij + a(k,i) * a(k,j);
      end

      error_frobenius = error_frobenius + ( bij - cij )^2;

    end
  end

  error_frobenius = sqrt ( error_frobenius );

  return
end
