Calculate eigenvectors of symbolic matrix?

66 views
Skip to first unread message

sonium

unread,
Mar 4, 2009, 5:52:49 AM3/4/09
to sage-support
Hi, I have problems calculating the eigenvectors of a symbolic matrix.
I tried:

a,b = var('a'),var('b')
M = matrix(SR,4,4,((a, 0, 0, 0), (0,-a,0,0), (0,0,a,0), (0,0,0,-a)))
M.eigenvectors_right()

what results in:
AttributeError: 'SymbolicArithmetic' object has no attribute 'degree'

and

P.<a,b> = PolynomialRing(QQ)
M = matrix(P,4,4,((a, 0, 0, 0), (0,-a,0,0), (0,0,a,0), (0,0,0,-a)))
M.eigenvectros_right()

what gives:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sage/sagenb/sage_notebook/worksheets/sonium/1/code/
26.py", line 6, in <module>
M.eigenvectors_right()
File "/home/sage/sage_install/sage-a/local/lib/python2.5/site-
packages/SQLAlchemy-0.4.6-py2.5.egg/", line 1, in <module>

File "matrix2.pyx", line 3054, in
sage.matrix.matrix2.Matrix.eigenvectors_right (sage/matrix/matrix2.c:
18020)
File "matrix2.pyx", line 3000, in
sage.matrix.matrix2.Matrix.eigenvectors_left (sage/matrix/matrix2.c:
17523)
File "matrix2.pyx", line 2755, in
sage.matrix.matrix2.Matrix.eigenspaces_left (sage/matrix/matrix2.c:
16250)
File "matrix2.pyx", line 1058, in sage.matrix.matrix2.Matrix.fcp
(sage/matrix/matrix2.c:7456)
File "polynomial_element.pyx", line 2288, in
sage.rings.polynomial.polynomial_element.Polynomial.factor (sage/rings/
polynomial/polynomial_element.c:18681)
NotImplementedError


:(

Jason Grout

unread,
Mar 4, 2009, 6:44:44 AM3/4/09
to sage-s...@googlegroups.com
sonium wrote:
> Hi, I have problems calculating the eigenvectors of a symbolic matrix.
> I tried:
>
> a,b = var('a'),var('b')
> M = matrix(SR,4,4,((a, 0, 0, 0), (0,-a,0,0), (0,0,a,0), (0,0,0,-a)))
> M.eigenvectors_right()
>
> what results in:
> AttributeError: 'SymbolicArithmetic' object has no attribute 'degree'
>

This comes from us not having a special implementation of the eigen
functions for symbolic matrices (i.e., using maxima). For now, you can do:

sage: a,b = var('a'),var('b')
sage: M = matrix(SR,4,4,((a, 0, 0, 0), (0,-a,0,0), (0,0,a,0), (0,0,0,-a)))
sage: M._maxima_().eigenvectors().sage()
[[[-a, a], [2, 2]], [0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 0]]


See
http://maxima.sourceforge.net/docs/manual/en/maxima_25.html#Item_003a-eigenvectors
to understand the output of the command.

The specific error you received came from there not being a .degree()
method for a symbolic polynomial.


I'm not sure what is going on here...

Thanks,

Jason

Alexander Hupfer

unread,
Mar 4, 2009, 7:40:27 AM3/4/09
to sage-support
thank you for your quick reply.

Just for sake of documentation:

the output reads as [[[eigenvalue1, eigenvalue2],[multiplicity of
EVal1, multiplicity of EVal2]], Eigenvect of EVal1,..., Eigenvect
EVal1, Eigenvect of EVal2,..., Eigenvect of EVal2]

On 4 Mrz., 12:44, Jason Grout <jason-s...@creativetrax.com> wrote:
> sonium wrote:
> > Hi, I have problems calculating the eigenvectors of a symbolic matrix.
> > I tried:
>
> > a,b = var('a'),var('b')
> > M = matrix(SR,4,4,((a, 0, 0, 0), (0,-a,0,0), (0,0,a,0), (0,0,0,-a)))
> > M.eigenvectors_right()
>
> > what results in:
> > AttributeError: 'SymbolicArithmetic' object has no attribute 'degree'
>
> This comes from us not having a special implementation of the eigen
> functions for symbolic matrices (i.e., using maxima).  For now, you can do:
>
> sage: a,b = var('a'),var('b')
> sage: M = matrix(SR,4,4,((a, 0, 0, 0), (0,-a,0,0), (0,0,a,0), (0,0,0,-a)))
> sage: M._maxima_().eigenvectors().sage()
> [[[-a, a], [2, 2]], [0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 0]]
>
> Seehttp://maxima.sourceforge.net/docs/manual/en/maxima_25.html#Item_003a...

Jason Grout

unread,
Mar 4, 2009, 12:22:16 PM3/4/09
to sage-s...@googlegroups.com
Alexander Hupfer wrote:
> thank you for your quick reply.
>
> Just for sake of documentation:
>
> the output reads as [[[eigenvalue1, eigenvalue2],[multiplicity of
> EVal1, multiplicity of EVal2]], Eigenvect of EVal1,..., Eigenvect
> EVal1, Eigenvect of EVal2,..., Eigenvect of EVal2]


Interestingly, there doesn't seem to be an easy way to tell (from the
output) which eigenvector goes with which eigenvalue in the following
examples:

sage: M = matrix(SR,4,4, [[0,1,0,0],[0,0,0,0],[0,0,2,0],[0,0,0,2]]); M

[0 1 0 0]
[0 0 0 0]
[0 0 2 0]
[0 0 0 2]
sage: M._maxima_().eigenvectors().sage()
[[[0, 2], [2, 2]], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
sage: M = matrix(SR,4,4, [[0,0,0,0],[0,0,0,0],[0,0,2,1],[0,0,0,2]]); M

[0 0 0 0]
[0 0 0 0]
[0 0 2 1]
[0 0 0 2]
sage: M._maxima_().eigenvectors().sage()
[[[0, 2], [2, 2]], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]]

I believe MMA helps you by making sure that the list of eigenvectors is
exactly as long as the sum of the multiplicities by inserting zero
vectors where needed (in other words, you can just count multiplicities
to get a generating set for the eigenspace). The Sage
eigenvectors_right command avoids the problem by returning a set of
eigenvectors associated with each eigenvalue.

Thanks,

Jason

alex

unread,
Mar 10, 2009, 11:04:45 AM3/10/09
to sage-support
i have trouble in collecting the eigenvectors to form an eigenvector
matrix (in the order given by the eigenvalue computation...).

How can i do this ?

I have tried all matrix commands.

THX.
> eigenvectors_right command avoids the problem by returning a set ofeigenvectorsassociated with each eigenvalue.
>
> Thanks,
>
> Jason
>
>
>
> > On 4 Mrz., 12:44, Jason Grout <jason-s...@creativetrax.com> wrote:
> >> sonium wrote:
> >>> Hi, I have problems calculating theeigenvectorsof asymbolicmatrix.
> >>> I tried:
> >>> a,b = var('a'),var('b')
> >>> M = matrix(SR,4,4,((a, 0, 0, 0), (0,-a,0,0), (0,0,a,0), (0,0,0,-a)))
> >>> M.eigenvectors_right()
> >>> what results in:
> >>> AttributeError: 'SymbolicArithmetic' object has no attribute 'degree'
> >> This comes from us not having a special implementation of the eigen
> >> functions forsymbolicmatrices (i.e., using maxima). For now, you can do:

Jason Grout

unread,
Mar 10, 2009, 2:54:45 PM3/10/09
to sage-s...@googlegroups.com
alex wrote:
> i have trouble in collecting the eigenvectors to form an eigenvector
> matrix (in the order given by the eigenvalue computation...).
>
> How can i do this ?
>
> I have tried all matrix commands.
>


For a "normal" matrix (i.e., not symbolic), you'll probably want to use
the .eigenmatrix_right() method. For a symbolic matrix (until we fix it
to be consistent), you can generate the eigenvectors as below and just
do something like:


matrix(M._maxima_().eigenvectors().sage()[1:]).transpose()

This gets all of the eigenvectors, puts them as rows in a matrix, then
transposes the matrix so that they are actually columns.

Jason
Reply all
Reply to author
Forward
0 new messages