Ask Your Question

Finding complex roots

asked 2015-05-02 16:05:56 +0200

Oderyn gravatar image

updated 2015-05-05 18:13:04 +0200

rws gravatar image

So, what is the best way to find complex roots of polynomials?

I only found that one:

sage: from sage.rings.polynomial.complex_roots import complex_roots
sage: x=polygen(ZZ)
sage: complex_roots(1.3*x^3-x^2-5*x-1)
[(-1.479272103982880?, 1), (-0.2113935621844148?, 1),
(2.459896435398064?, 1)]

Should I use that? Isn't there an inbuilt function? Even PARI/GP has one, namely polroots...

And why is the x casted as an element of $\mathbb{Z}[X]$, why not $\mathbb{C}[X]$? Can somebody explain that to me?

Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-05-02 16:29:21 +0200

tmonteil gravatar image

When you write

sage: x = polygen(ZZ)

you define the variable x as an element of the polynomial ring in one variable over the integers:

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

Hence you can define any polynomial in $\mathbb{Z}[x]$ and find its roots as follows:

sage: P = 2*x - 3
sage: P
2*x - 3
sage: P.roots()

As you can see, there is no root in $\mathbb{Z}$, if you want to have the roots in $\mathbb{Q}$:

sage: P.roots(QQ)
[(3/2, 1)]

You can also change the parent of the polynomial to be the rationals:

sage: Q = P.change_ring(QQ)
sage: Q
2*x - 3
sage: Q.parent()
Univariate Polynomial Ring in x over Rational Field
sage: Q.roots()
[(3/2, 1)]

Of course you can define x as being a monomial over the retionals:

sage: x = polygen(QQ)
sage: x.parent()
Univariate Polynomial Ring in x over Rational Field

Concerning complex roots, let me just add that the rings CC and CDF (faster) are floating -point approximation (fast, but inexact), there is also the field of algebraic numbers to work in:

sage: x = polygen(ZZ)
sage: P = x^2-2
sage: P.roots()
sage: P.roots(QQ)
sage: P.roots(CC)
[(-1.41421356237310, 1), (1.41421356237310, 1)]

sage: P.roots(CC)[0][0]^2
sage: P.roots(CC)[0][0]^2 == 2
sage: P.roots(CC)[0][0]^2 - 2

sage: P.roots(QQbar)
[(-1.414213562373095?, 1), (1.414213562373095?, 1)]
sage: P.roots(QQbar)[0][0]^2 == 2
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2015-05-02 16:05:56 +0200

Seen: 3,706 times

Last updated: May 02 '15