In Lapack (zhseqr) and matlab, the eigenvalues of a complex matrix are computed successfully. I notice that QR iteration or algorithm is involved with that process. QR iteration repeats to call QR decomposition of R*Q from the previous step.
Here is my question: QR decomposition in Lapack (zgeqrf) produces real diagonal entries. QR iteration should make the complex diagonal entries of the upper triangular matrix as a result. For example,
>> A = [0 2; 1 3*i];
This non-symmetric A is known to have eigenvalues of i and 2i. Since the magnitudes of eigenvalues are distinct, the QR iteration probably converges well without any special shift. So, we have the upper triangular matrix from schur decomposition or QR iteration in Lapack:
>> schur(A) ans = 0 + 1i -3 + 0.00066061i 0 + 0i 1.4366e-18 + 2i
Now I tried to implement QR iteration to see how the algorithm works:
num_iter = 200; [Q,R] = qr (A); for ii=1:num_iter, [Q,R] = qr (R*Q); end
But the result R has
R = -2 + 0i 2.4535e-13 - 3i 0 + 0i 1 + 0i
My code converged to absolute values of eigenvalues, not to complex eigenvalues.
What is wrong with my code?