Skip to main content

Linear Algebra with SageMath Learn math with open-source software

Section 12.1 Diagonalization of a Matrix

A matrix \(A\) is said to be similar to matrix \(B\) if there exists an invertible matrix \(P\) such that \(P^{-1} A P = B\)
Sage offers the method is_similar() to check if two given matrices are similar.
Similar matrices have the same eigenvalues.
The matrix \(A\) is diagonalizable if it is similar to a diagonal matrix, i.e, there is an invertible matrix \(P\) and diagonal matrix \(D\) such that \(P^{-1} A P = D\text{.}\) We say in this case that the matrix \(P\) diagonalizes \(A\text{.}\)
To check if a matrix is diagonalizable, Sage provides the built-in function is_diagonalizable()
To obtain the diagonal form and the matrix that diagonalizes \(A\text{,}\) we can use the diagonalization() method whose output is the pair of matrices \((D,P)\text{.}\)
The following conditions are equivalent:
  1. \(A\) is diagonalizable.
  2. There exists a linearly independent set of eigenvectors \(v_1, v_2, ..., v_n\) of \(A\text{.}\) In this case, the matrix \(D\) is diagonal with the eigenvalues of \(A\) on the diagonal, and the matrix \(P\) has the eigenvectors \(v_1, v_2, ..., v_n\) as its columns.
  3. The geometric multiplicity of each eigenvalue of \(A\) is equal to its algebraic multiplicity.
Therefore, we can apply, for instance, condition 3 to determine whether a matrix is diagonalizable. To calculate the geometric multiplicites of the eigenvalues, we first compute the eigenspaces as shown in the previous chapter, and then determine their dimensions.
Then we check whether the geometric multiplicities coincide with the algebraic ones.
We obtained that the geometric multiplicity of the second eigenvalue is not equal to its algebraic multiplicity, confirming that the matrix \(A\) is not diagonalizable.
Repeating the process for the matrix \(B\text{:}\)
We obtain that they are all equal for all the eigenvalues and therefore B is diagonalizable.
Alternatively can also leverage Sage built-in eigenmatrix_right() method to apply the second condition.
If the second matrix \(P\) of the pair has zero columns, then this means that there were not enough eigenvectors to satisfy the second condition, so the matrix is not diagonalizable.
We can visualize the zero column in the second matrix, or we can ask Sage to check directly:
Therefore verifying that the matrix \(A\) is not diagonalizable. Observe that in this case, \(AP=PD\text{:}\)
But the equation \(P^{-1}AP= D\) is not satisfied since \(P\) is not invertible.
Using the same method for the matrix \(B\text{:}\)
We obtain that the second matrix is not singular, and therefore the matrix is diagonalizable. We can explicitly see the matrices \(D\) and \(P\) of the diagonalization.
Observe that in this case, both equalities \(BP=PD\) and \(P^{-1}BP= D\) are satisfied.