qzswitch <- function(i=1,a=as.complex(1),b=as.complex(1),q=as.complex(1),z=as.complex(1)) { ## Takes U.T. matrices a, b, orthonormal matrices q,z, interchanges ## diagonal elements i and i+1 of both a and b, while maintaining ## qaz' and qbz' unchanged. If diagonal elements of a and b ## are zero at matching positions, the returned a will have zeros at both ## positions on the diagonal. This is natural behavior if this routine is used ## to drive all zeros on the diagonal of a to the lower right, but in this case ## the qz transformation is not unique and it is not possible simply to switch ## the positions of the diagonal elements of both a and b. realsmall <- 1e-7; ##realsmall<-1e-3; q <- t(Conj(q)) #This is needed because the code was originally for matlab, where it is q'az' that # is preserved. A <- a[i,i]; d <- b[i,i]; B <- a[i,(i+1)]; e <- b[i,(i+1)] c <- a[i+1,i+1]; f <- b[i+1,i+1] ## a[i:(i+1),i:(i+1)]<-[A B; 0 c] ## b[i:(i+1),i:(i+1)]<-[d e; 0 f] if (abs(c)