exact eigenvalues

114 views
Skip to first unread message

ccandide

unread,
Nov 7, 2013, 12:00:36 PM11/7/13
to sage-s...@googlegroups.com
I dont' understand why Sage is unable to give an exact expression for the eigenvalues of the following matrix :

sage: A= matrix([[0,1],[1,-2]])
sage: [a for a,_,_ in A.eigenvectors_right()]
[-2.414213562373095?, 0.4142135623730951?]


The characteristic polynomial is very simple :

sage: A.charpoly()                          
x^2 + 2*x - 1


and Sage is able to compute the roots in exact form :

sage: (x^2 + 2*x - 1).roots()               
[(-sqrt(2) - 1, 1), (sqrt(2) - 1, 1)]
sage:

What is very surprising is that Sage does recognise the exact values :

sage: L=(x^2 + 2*x - 1).roots(multiplicities=False);L
[-sqrt(2) - 1, sqrt(2) - 1]
sage: [a for a,_,_ in A.eigenvectors_right()]==L    
True
sage:


Is there any way to convert the charpoly result to a symbolic expression ?


Note that Maple gives the result in symbolic form:

> restart;with(LinearAlgebra):
>
> A:=Matrix([<0,1>,<1,-2>]);

                                 [0     1]
                            A := [       ]
                                 [1    -2]

> Eigenvalues(A);

                             [      1/2]
                             [-1 + 2   ]
                             [         ]
                             [      1/2]
                             [-1 - 2   ]


John H Palmieri

unread,
Nov 7, 2013, 12:19:39 PM11/7/13
to sage-s...@googlegroups.com
On Thursday, November 7, 2013 9:00:36 AM UTC-8, ccandide wrote:
I dont' understand why Sage is unable to give an exact expression for the eigenvalues of the following matrix :

sage: A= matrix([[0,1],[1,-2]])
sage: [a for a,_,_ in A.eigenvectors_right()]
[-2.414213562373095?, 0.4142135623730951?]

I think it is an exact expression, but it's not printed very well.

sage: b = A.eigenvectors_right()[0][0]
sage: b
-2.414213562373095?

sage: parent(b)
Algebraic Field
sage: (b+1)^2  # note no imprecision in this answer
2
sage: b == -sqrt(2) - 1
True
sage: b.degree()
2
sage: b.as_number_field_element()
(Number Field in a with defining polynomial y^2 - 2,
 a - 1,
 Ring morphism:
  From: Number Field in a with defining polynomial y^2 - 2
  To:   Algebraic Real Field
  Defn: a |--> -1.414213562373095?)

sage: b._exact_value()
a - 1 where a^2 - 2 = 0 and a in -1.414213562373095?



Nils Bruin

unread,
Nov 7, 2013, 12:28:31 PM11/7/13
to sage-s...@googlegroups.com
On Thursday, November 7, 2013 9:00:36 AM UTC-8, ccandide wrote:
I dont' understand why Sage is unable to give an exact expression for the eigenvalues of the following matrix :

sage: A= matrix([[0,1],[1,-2]])
sage: [a for a,_,_ in A.eigenvectors_right()]
[-2.414213562373095?, 0.4142135623730951?]

It does have an exact expression for them. It just prints an approximation to them. The "?" is a bit of a give-away that there might be more to it than just plain floats here:

sage: v=[a for a,_,_ in A.eigenvectors_right()][0]
sage: parent(v)
Algebraic Field
sage: v.minpoly()

x^2 + 2*x - 1

The reason sage decides to use this representation is because printing these things in terms of sqrt(2) quickly runs out of steam:
sage: M=matrix(5,5,[0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,-3,-1,0,0,0 ])
sage: M.eigenvectors_right()[0][0]
-1.132997565885066?
(see what you get in maple for that)

Perhaps with A=matrix(SR,[[0,1],[1,-2]]) you get an answer that looks more comfortable to you.

ccandide

unread,
Nov 7, 2013, 1:22:17 PM11/7/13
to sage-s...@googlegroups.com


Le jeudi 7 novembre 2013 18:28:31 UTC+1, Nils Bruin a écrit :
On Thursday, November 7, 2013 9:00:36 AM UTC-8, ccandide wrote:
I dont' understand why Sage is unable to give an exact expression for the eigenvalues of the following matrix :

sage: A= matrix([[0,1],[1,-2]])
sage: [a for a,_,_ in A.eigenvectors_right()]
[-2.414213562373095?, 0.4142135623730951?]

It does have an exact expression for them. It just prints an approximation to them. The "?" is a bit of a give-away that there might be more to it than just plain floats here:
 
 

sage: v=[a for a,_,_ in A.eigenvectors_right()][0]
sage: parent(v)
Algebraic Field
sage: v.minpoly()
x^2 + 2*x - 1


OK, I get it!!



The reason sage decides to use this representation is because printing these things in terms of sqrt(2) quickly runs out of steam:
sage: M=matrix(5,5,[0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,-3,-1,0,0,0 ])
sage: M.eigenvectors_right()[0][0]
-1.132997565885066?
(see what you get in maple for that)


Maple gives the following :

A:=Matrix(5,5,[0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,-3,-1,0,0,0 ]);

                         [ 0     1    0    0    0]
                         [                       ]
                         [ 0     0    1    0    0]
                         [                       ]
                    A := [ 0     0    0    1    0]
                         [                       ]
                         [ 0     0    0    0    1]
                         [                       ]
                         [-3    -1    0    0    0]

> Eigenvalues(A)[1];
>

                                5
                   RootOf(3 + _Z  + _Z, index = 1)

I don't how Maple is able to work symbolically with that.

 


 

Perhaps with A=matrix(SR,[[0,1],[1,-2]]) you get an answer that looks more comfortable to you.

Exactly what I was looking for, many thanks.

ccandide

unread,
Nov 7, 2013, 1:24:44 PM11/7/13
to sage-s...@googlegroups.com


Le jeudi 7 novembre 2013 18:19:39 UTC+1, John H Palmieri a écrit :

sage: b._exact_value()
a - 1 where a^2 - 2 = 0 and a in -1.414213562373095?



It is reassuring to see that we can recover the exact value! thanks
Reply all
Reply to author
Forward
0 new messages