Skip to main content
Logo image

Section 4.7 Some Sage examples

Here are some common uses of Sage with linear algebra applications.

Subsection 4.7.1 Eigenvalues, eigenvectors, and diagonalization

Generate a diagonalizable \(8\times 8\) integer matrix.
Compute the characteristic polynomial and factor it. Since we asked for a matrix which is known to be diagaonalizable, the characteristic polynomial will necessarily factor into linear factors. To make things more interesting, run the Sage script until you get a characteristic polynomial with some algebraic multiplicities greater than one.
Compute the eigenvalues and bases for the corresponding eigenspaces. The output is a list giving each eigenvalue and a basis for the corresponding eigenspace. Watch for these to show up as the columns of the change of basis matrix.
Another way of getting the same data is below. The output is a list of triples of the form [eigenvalue, list of independent eigenvectors,algebraic multiplicity].
The diagonalized matrix \(D=P^{-1}BP\) where \(P\) is the change of basis matrix whose columns are the eigenvectors spanning the eigenspaces.

Subsection 4.7.2 Rational and Jordan canonical forms

This section contains more advanced material. Example slightly modified from the Sage Reference Manual
 1 
doc.sagemath.org/pdf/en/reference/matrices/matrices.pdf
.
We see the factored characteristic polynomial is divisible by a quadratic which is irreducible over \(\Q\text{,}\) so the matrix will not be diagonalizable. It will have a rational canonical form, but not a Jordan form over \(\Q.\)
Here is the minimal polynomial, the largest of the invariant factors.
Here is a list of the invariant factors, given as a lists of coefficients of the polynomials they represent.
Here we turn those lists into polynomials. The rational canonical form is a block diagonal matrix with each block being the companion matrix.
The matrix \(C\) is not diagaonalizable over any field since the minimal polynomial has a multiple root.
Since the minimal(characteristic) polynomial has an irreducible quadratic factor, we need to extend the field \(\Q\) to a quadratic extension which contains a root in order to produce a Jordan form.
Now \(C\) has a Jordan canonical form over the field \(K.\)
Example taken from the Sage Reference Manual
 2 
doc.sagemath.org/pdf/en/reference/matrices/matrices.pdf
, has all invariant factors a power of \((x-2).\)