The process of balancing a matrix applies similarity transformations to make the rows and columns have comparable norms. This is useful, for example, to reduce roundoff errors in the solution of eigenvalue problems. Balancing a matrix A consists of replacing A with a similar matrix
A' = D^(-1) A D
where D is a diagonal matrix whose entries are powers of the floating point radix.
This function replaces the matrix A with its balanced counterpart and stores the diagonal elements of the similarity transformation into the vector D.