Eigenvalues are the roots of the characteristic polynomial (Theorem EMRCP), which should be obvious from the factored version, including their (algebraic) multiplicities. Of course, it can be very easy to get these in Sage.
Create the singular matrices \(A-\lambda I_6\) for each eigenvalue (we will choose to do two with “random” choices for the eigenvalue). Row-reducing these matrices will exhibit their nonzero nullity.
As always we want the “right” versions of the relevant commands. Eigenspaces are in the second parts of pairs, where the first part of each pair is the eigenvalue. Notice that they are vector spaces (with bases, etc). The basis vectors are Sage's version of a basis, with vectors from an echelonized matrix, typically with lots of zeros and ones in the first part of the vectors.
The eigenmatrix commands return pair of matrices. The first is a diagonal matrix with the eigenvalues on the diagonal. The second is a square matrix with linearly independent eigenvectors in the columns, and the order of the eigenvectors is the same as the order of the eigenvalues. That is, the eigenvector in column i of the second matrix is a basis vector for the eigenspace of the eigenvalue in column i of the first matrix.
Sometimes the dimension of an eigenspace (the geometric multiplicity) is strictly less than the number of times the eigenvalue appears as a root of the characteristic polynomial. This is the case with C next, but was not the case with A above.
A totally random matrix is unlikely to have a characteristic polynomial that factors if we restrict ourseves to the rationals. But we can find all the roots over \(\overline{Q}\text{,}\) the set of all algebraic numbers. (This is the set of all real roots of all possible polynomials with integer coefficients.)
︡88c923f3-5f20-4857-a7b8-ba5b0f667e58︡
︠9d157496-7f6a-4fff-a66a-f155d653cd12︠
D = random_matrix(QQ, 10)
D
︡6b0707b9-d384-4d73-adea-8ebd4839c06e︡
︠2c9239af-282b-4cf3-afc1-940524e6db64︠
p = D.characteristic_polynomial()
p.factor()
︡9802b4b5-3ed6-4a95-ad92-f37f9a480136︡
︠6cf7facb-0fad-4547-ab21-e1561f05707b︠
p.roots(ring=QQbar, multiplicities=False)
︡6e755701-201c-4e71-a533-715c77b8d385︡
︠ef3649d5-a05c-4c33-ae97-2097d1f99cc1︠
%auto
%html(hide=True)
If we make a “block diagonal” matrix, then the characteristic polynomial will definitely factor some
︡1a0505ee-a9e0-45b4-a99d-0bea3bb254e1︡
︠60b65cc4-b7da-4735-accf-9db87e421970︠
E = block_diagonal_matrix( [random_matrix(QQ, 5), random_matrix(QQ, 5)])
E
︡ad064630-af87-490a-aec7-e659ec73f8c7︡
︠9749e9f2-aa12-41a2-ac9f-475904588514︠
p = E.charpoly()
p.factor()
︡cac14aa3-c4ee-47f8-aac1-909fa9302b53︡
︠02ed427e-6434-42a4-ab51-ce16dbf1b2d1︠
%auto
%html(hide=True)
Finally a large example, illustrating how fast Sage is at making characteristic polynomials and at factoring.
︡5d44a862-7c7a-4195-a54a-619876477095︡
︠1f253dea-0577-4081-a5d5-0479cf016810︠
F = block_diagonal_matrix( [random_matrix(QQ, 50), random_matrix(QQ, 50)])
p = F.charpoly()
p.factor()
︡d3f083d7-eec5-45cd-a62b-c204cc3cea4f︡
︠b12b2bef-2cee-423b-afad-b70bbc8f86ad︠
%auto
%html(hide=True)
This is such a common operation, that Sage has a shorthand method for the Factored Characteristic Polynomial, namely .fcp().
If we use CDF (Complex Double Field) for the number system of the entries of our matrix, we get (good) approximate values for eigenvalues. (If we are OK with the approximate nature, these routines are very, very fast.)
︡111ab51f-f3fb-43b0-a427-b071a87093f2︡
︠d04fb04c-0300-4f4b-a08d-73de587d9009︠
G = random_matrix(QQ, 300)
H = G.change_ring(CDF)
H.eigenvalues()
︡3d98d581-2952-4956-a45f-2c30a8825226︡
︠b645e1a7-3c08-4f9e-a6d3-5ff8fa08c6af︠
%auto
%html(hide=True)