# eigenvalues vs roots of characteristic polynomial

Hi,

Sorry if this is a stupid question but I am struggling to make Sage compute the exact eigenvalues of a matrix. I am also confused that when I ask for the roots of the characteristic polynomial Sage answers with complex roots... I am new to Sage so please forgive me :)

Here is my worksheet:

sage: A = matrix([[1, 1, 2], [1, -2, 0], [2, 0, 1]])
sage: A
[ 1  1  2]
[ 1 -2  0]
[ 2  0  1]
sage: A.eigenvalues()
[-2.439311671683875?, -0.6611203141265045?, 3.100431985810380?]
sage: x = var('x')
sage: H = A.charpoly()
sage: H
x^3 - 8*x - 5
sage: H.roots()
[]
sage: (x^3-8*x-5).roots()
[(-1/2*(1/18*I*sqrt(1373)*sqrt(3) + 5/2)^(1/3)*(I*sqrt(3) + 1) + 1/3*(4*I*sqrt(3) - 4)/(1/18*I*sqrt(1373)*sqrt(3) + 5/2)^(1/3),
1),
(-1/2*(1/18*I*sqrt(1373)*sqrt(3) + 5/2)^(1/3)*(-I*sqrt(3) + 1) + 1/3*(-4*I*sqrt(3) - 4)/(1/18*I*sqrt(1373)*sqrt(3) + 5/2)^(1/3),
1),
((1/18*I*sqrt(1373)*sqrt(3) + 5/2)^(1/3) + 8/3/(1/18*I*sqrt(1373)*sqrt(3) + 5/2)^(1/3),
1)]

edit retag close merge delete

Sort by » oldest newest most voted

If you type A.eigenvalues? you will get the documentation of this method that says " If the eigenvalues are roots of polynomials in QQ, then QQbar elements are returned that represent each separate root." which means that you will get the eigenvalues as algebraic numbers.

sage: [r.parent() for r in A.eigenvalues()]
[Algebraic Field, Algebraic Field, Algebraic Field]


Now, when you write H=A.charpoly() you define a polynomial over the integers:

sage: H=A.charpoly()
sage: H.parent()
Univariate Polynomial Ring in x over Integer Ring


In particular, the roots will be provided in this ring, and there is no integer root for this polynomial. If you want the algebraic roots, you can write:

sage: H.roots(ring=QQbar)
[(-2.439311671683875?, 1), (-0.6611203141265045?, 1), (3.100431985810380?, 1)]


You can check that the two lists are equal :

sage: H.roots(ring=QQbar, multiplicities=False) == A.eigenvalues()
True


As for your last polynomial, you define it over the symbolic, which explains why you get the roots as symbolic expressions.

more

Thanks for your help; and as I suspected the only problem was my own ignorance. Is there any way to ask Sage to give the roots in radicals form instead of decimal notation ?

( 2015-12-19 20:38:09 +0200 )edit

Here is an illustration of getting radical expressions for the eigenvalues.

sage: A = matrix([[1, 1, 2], [1, -2, 0], [2, 0, 1]])
sage: a, b, c = A.eigenvalues()
sage: a, b, c
(-2.439311671683875?, -0.6611203141265045?, 3.100431985810380?)
-1/2*(1/18*I*sqrt(1373)*sqrt(3) + 5/2)^(1/3)*(-I*sqrt(3) + 1) + 1/3*(-4*I*sqrt(3) - 4)/(1/18*I*sqrt(1373)*sqrt(3) + 5/2)^(1/3)


Note that they are not nice radical expressions.

more