We manufacture two matrices that are similar, and use Sage to check. A “unimodular” matrix is one with determinant 1. A unimodular matrix with integer entries will have an inverse with integer entries (that is a theorem).
{{{ A = random_matrix(ZZ, 10, x = -9, y = 9).change_ring(QQ) S = random_matrix(QQ, 10, algorithm='unimodular', upper_bound=9) B = S.inverse()*A*S A, B }}}This command seems to be broken. My fault.
{{{ A.is_similar(B) }}}
These two matrices are from the earlier demo for Section EE. First is diagonalizable, second is not. The easiest way to see the difference is with the eigenmatrix commands.
{{{ entries = [[-31, -23, -16, 12, 120, -17], [-3, 7, 0, -12, 60, -21], [-28, -14, -9, -4, 152, -30], [-36, -20, -16, -1, 192, -32], [-9, -5, -4, 0, 47, -8], [-1, 1, 0, -4, 20, -3]] A = matrix(QQ, entries) A }}}S, the matrix whose columns are eigenvectors, will “diagonalize” A.
{{{ D, S = A.eigenmatrix_right() D, S }}} {{{ S.inverse()*A*S == D }}}Here is an equivalent formulation.
{{{ A*S == S*D }}}Now for a matrix that is not diagonalizable.
{{{ entries = [[128, 20, 44, -50, 236, -18, -330, -565], [-23, -16, -5, 6, -40, 27, 62, 128], [-44, -12, -15, 16, -78, 20, 110, 207], [-2, 10, -4, 3, -10, -23, 20, -9], [-61, 5, -25, 27, -116, -26, 153, 225], [-12, -12, -1, 2, -20, 24, 34, 82], [-23, -3, -8, 9, -42, 2, 57, 99], [13, 6, 3, -4, 23, -12, -35, -72]] C = matrix(QQ, entries) C }}} {{{ D, S = C.eigenmatrix_right() D, S }}}The zero columns in S tell us that at least one eigenvalue has a geometric multiplicity strictly less than the algebraic multiplicity of the eigenvalue. So by Theorem DMFE the matrix C is not diagonalizable.
A second consequence of the zero columns of S is that it will not be an invertible matrix. But the output from Sage still obeys a fundamental relationship.
{{{ C*S == S*D }}}Perhaps simpler is the built-in function .is_diagonalizable().
{{{ A.is_diagonalizable() }}} {{{ C.is_diagonalizable() }}}
A matrix that is not diagonalizable will always be similar to a matrix that is almost diagonalizable. The “nearly diagonal” matrix is called the Jordan Canonical Form of the matrix. While beyond the scope of this course, here is Sage computing this canonical form for the matrix C. Notice the eigenvalues of C on the diagonal and the 1’s on the “super-diagonal”.
{{{ J, T = C.jordan_form(transformation=True) J, T }}}The transformation matrix, T, is invertible and will “almost diagonalize” C.
{{{ T.inverse()*C*T == J }}}Rational Canonical Form is another interesting version of this idea, try .rational_form().
{{{ }}}