I tried to implement the QR algorithm for non-symmetric matrices with complex entries to show to my students. The main part of the implementation was standard: the Householder reduction to the Hessenberg form, complex Given's rotations, etc. So far so good.
Now, if you do it without shifts, it will never converge if two eigenvalues have equal absolute values (which is not such an exceptional case: most real-valued matrices have conjugate pairs, the companion matrices of polynomials like $z^n-1$ have all their roots on the circle, etc., etc.). So, I needed to shift in some intelligent way.
Both Raleigh (shifting by the bottom right element) and Wilkinson (shifting by an eigenvalue of the bottom right $2\times 2$ matrix) fail: it is fairly easy to create the matrix (say, the same companion matrix of $z^n-1$, but not only) for which the complex QR algorithm using these shifts will cycle or converge to a matrix that is not upper triangular, but has some $2\times 2$ blocks instead. No clever modification of those seemed to help either.
So, my solution was to follow my favorite general principle: "If you don't know how to do something, do it at random". My shift for a single run is just a uniform complex number in the bottom Gershgorin disk (centered at $a_{n,n}$ and of radius $|a_{n,n-1}|$). It seems to work like a charm (I couldn't create a matrix for which it would fail and it requires about 5 QR iterations per eigenvalue with relative precision $10^{-13}$ for the below the diagonal values in the "reasonable" cases), but for the life of mine I cannot figure out why.
All literature I know just discusses why guessing a shift sufficiently close to a true eigenvalue accelerates the convergence, and that I understand. However, in this case, one can start with small eigenvalues and have quite large below diagonal entries, so at least in the beginning I do not see why it is any better than shifting by a totally random number at each iteration, which would not achieve much (or would it?). So, two questions:
What is the usually recommended shift for the complex case?
Why does my home-made contraption work? ${}{}{}{}{}$