Ask Your Question

Revision history [back]

The errors message are quite clear: you should provide a field that is exact. This is because of numerical stability issues in the algorithms.

Let us try with the first exact field that contains ZZ that we have in mind:

sage: m = matrix(QQ,[[2, -3], [1, 0]])
sage: m.diagonalization()
ValueError: not diagonalizable over Rational Field

The answer tells that the eigenvalues are not rational, so we need to use a larger field: the field of algebraic numbers:

sage: m = m.change_ring(QQbar)
sage: m.diagonalization()
(
[1 - 1.414213562373095?*I                        0]  [                                          1                                           1]
[                       0 1 + 1.414213562373095?*I], [0.3333333333333334? + 0.4714045207910317?*I 0.3333333333333334? - 0.4714045207910317?*I]
)

Wile the results looks numerical, but it is only for screen printing, they are actually genuine algebraic numbers, see for the first entry:

sage: m.diagonalization()[0][0][0]
1 - 1.414213562373095?*I
sage: parent(m.diagonalization()[0][0][0])
Algebraic Field
sage: (m.diagonalization()[0][0][0]).minpoly()
x^2 - 2*x + 3

Now, if you want to get only numerical result, you can do:

sage: m.diagonalization()[0].change_ring(CDF)
[1.0 - 1.414213562373095*I                       0.0]
[                      0.0 1.0 + 1.414213562373095*I]
sage: m.diagonalization()[1].change_ring(CDF)
[                                       1.0                                        1.0]
[0.33333333333333337 + 0.4714045207910317*I 0.33333333333333337 - 0.4714045207910317*I]

By the way, instead of changinf the base ring of the matrix, you can change it for the computation of the diagonalization:

sage: m = matrix([[2, -3], [1, 0]])
sage: m.diagonalization(QQbar)
(
[1 - 1.414213562373095?*I                        0]  [                                          1                                           1]
[                       0 1 + 1.414213562373095?*I], [0.3333333333333334? + 0.4714045207910317?*I 0.3333333333333334? - 0.4714045207910317?*I]
)