title: Matlab Not Returning Orthonormal Matrix of Eigenvectors
body: <p>When I try to find the eigen-decomposition of a matrix in Matlab that has a repeated eigenvalue but is NOT defective, it is not returning an orthonormal matrix of eignevectors. For example:</p>
  
  <pre><code>k = 5;
  repeats = 1;
  
  % First generate a random matrix of eignevectors that is orthonormal
  V = orth(rand(k));
  
  % Now generate a vector of eigenvalues with the given number of repeats
  D = rand(k,1);
  for i = 1:repeats
      % Put one random value into another (note this sometimes will result in
      % less than the given number of repeats if we ever input the same
      % number)
      D(ceil(k*rand())) = D(ceil(k*rand()));
  end
  
  A = V'*diag(D)*V;
  
  % Now test the eignevector matrix of A
  [V_A, D_A] = eig(A);
  
  disp(V_A*V_A' - eye(k))
  </code></pre>
  
  <p>I am finding that my matrix of eigenvectors <code>V_A</code> is not orthogonal i.e. <code>V_A*V_A'</code> is not equalling the identity matrix (taking into account rounding errors).</p>
  
  <p>I was under the impression that if my matrix was real and symmetric then Matlab would return an orthogonal matrix of eigenvectors, so what is the issue here?</p>