// Reverse preconditioning step 2: inverse balancing. // Done in two steps: inverse scaling, then inverse permutation // inverse scaling (diagonal transformation) for (octave_idx_type i = 0; i < nc; i++) for (octave_idx_type j = 0; j < nc; j++) retval(i,j) *= dscale(i) / dscale(j); OCTAVE_QUIT; // construct balancing permutation vector Array iperm (nc); for (octave_idx_type i = 0; i < nc; i++) iperm(i) = i; // initialize to identity permutation // trailing permutations must be done in reverse order for (octave_idx_type i = nc - 1; i >= ihi; i--) { octave_idx_type swapidx = static_cast (dpermute(i)) - 1; octave_idx_type tmp = iperm(i); iperm(i) = iperm(swapidx); iperm(swapidx) = tmp; } // leading permutations in forward order for (octave_idx_type i = 0; i < (ilo-1); i++) { octave_idx_type swapidx = static_cast (dpermute(i)) - 1; octave_idx_type tmp = iperm(i); iperm(i) = iperm(swapidx); iperm(swapidx) = tmp; } // construct inverse balancing permutation vector Array invpvec (nc); for (octave_idx_type i = 0; i < nc; i++) invpvec(iperm(i)) = i; // Thanks to R. A. Lippert for this method OCTAVE_QUIT; ComplexMatrix tmpMat = retval; for (octave_idx_type i = 0; i < nc; i++) for (octave_idx_type j = 0; j < nc; j++) retval(i,j) = tmpMat(invpvec(i),invpvec(j)); // Reverse preconditioning step 1: fix trace normalization.