balance
Balances a matrix by a diagonal similarity transformation to improve eigenvalue accuracy.
Category: Mathematics > Linear Algebra
Syntax
B = balance(A)
Returns the balanced matrix.
[T, B] = balance(A)
Also returns the transformation T with B = T\A*T.
[S, P, B] = balance(A)
Returns the scaling vector S and the permutation vector P separately.
B = balance(A, 'noperm')
Only scales; does not permute rows and columns.
Description
When the entries of a matrix vary over many orders of magnitude, rounding errors can spoil the computed eigenvalues. Balancing rescales rows and columns, by powers of two so that no rounding is introduced, until the norms of corresponding rows and columns are comparable.
Because B is similar to A, eig(B) equals eig(A) in exact arithmetic, but is typically computed more accurately. eig already balances internally by default.
Input arguments
A- Square matrix.
Output arguments
B- Balanced matrix, similar to
Aand so with the same eigenvalues. T- Similarity transformation (diagonal scaling combined with a permutation).
Example
A badly scaled matrix
A = [1 100 10000; 0.01 1 100; 0.0001 0.01 1];
[T, B] = balance(A);
B
diag(T)'
Output
B = 3×3
1.0000 1.5625 1.2207
0.6400 1.0000 0.7812
0.8192 1.2800 1.0000
ans = 1×3
512.0000 8.0000 0.0625