function U = gram_schmidt_naive ( A )

%*****************************************************************************80
%
%% gram_schmidt_naive() applies the naive Gram-Schmidt orthonormalization process.
%
%  Discussion:
%
%    Because of roundoff, the orthonormalization process may have
%    significant errors.
%
%    In fact, given a matrix with M < N, the process is unlikely to notice
%    that no more than M columns can be linearly independent.
%
%    In exact arithmetic, linearly dependent columns would be returned
%    as 0 columns.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    20 January 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real A(M,N), a matrix whose columns are to be orthonormalized.
%
%  Output:
%
%    real U(M,N), the matrix with orthonormalized columns.
%
  [ m, n ] = size ( A );

  U = zeros ( m, n );

  for j = 1 : n

    v = A(:,j);

    for j2 = 1 : j - 1
      dot = v' * U(:,j2);
      v = v - dot * U(:,j2);
    end

    v_norm = norm ( v );
    if ( 0.0 < v_norm )
      U(:,j) = v / v_norm;
    end

  end

  return
end
