Ask Your Question

Characteristic polynomial wont be used in solve

asked 2017-11-23 18:18:11 +0200

Poetastrophe gravatar image

updated 2023-05-19 22:10:02 +0200

FrédéricC gravatar image

When I try to find roots in a characteristic polynomial it gives me errors:

sage: #Diagonalmatrix
....: A=matrix([[1,-1,2],
....:         [-1,1,2],
....:         [2,2,-2]])
....: var('x')
....: poly=A.characteristic_polynomial()
....: eq1=solve(poly==0,x)
TypeError        Traceback (most recent call last)
<ipython-input-86-fee7a7de2ea1> in <module>()
      7 var('x')
      8 poly=A.characteristic_polynomial()
----> 9 eq1=solve(poly==Integer(0),x)

/usr/lib/python2.7/site-packages/sage/symbolic/relation.pyc in solve(f, *args, **kwds)
    817     if not isinstance(f, (list, tuple)):
--> 818         raise TypeError("The first argument must be a symbolic expression or a list of symbolic expressions.")
    820     if len(f)==1:

TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.

What can I do in order to use the polynomial in an equation I wish to solve?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2017-11-23 18:32:35 +0200

tmonteil gravatar image

As you can see, poly is a genuine polynomial, not a symbolic expression:

sage: poly.parent()
Univariate Polynomial Ring in x over Integer Ri

You can get its roots as follows:

sage: poly.roots()
[(-4, 1), (2, 2)]

So, you can see, that it has root -4 wirh multiplicity 1 anr roor 2· with multiplicity 2.

Note that poly. == 0 is the boolean False, since the polynomial is not the zero polynomial:

sage: poly == 0

If you really want to use solve, you need to transform the polynomial into a symbolic expression as follows:

sage: SR(poly)
x^3 - 12*x + 16
sage: SR(poly).parent()
Symbolic Ring

Then, you can do:

sage: solve(SR(poly),x)
[x == -4, x == 2]
edit flag offensive delete link more


Thanks a lot!

Poetastrophe gravatar imagePoetastrophe ( 2017-11-23 18:34:58 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2017-11-23 18:18:11 +0200

Seen: 606 times

Last updated: Nov 23 '17