Ask Your Question

# Finding complex roots

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 close merge delete

## 1 Answer

Sort by » oldest newest most voted

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
2.00000000000000
sage: P.roots(CC)[0][0]^2 == 2
False
sage: P.roots(CC)[0][0]^2 - 2
4.44089209850063e-16

sage: P.roots(QQbar)
[(-1.414213562373095?, 1), (1.414213562373095?, 1)]
sage: P.roots(QQbar)[0][0]^2 == 2
True
more

## Your Answer

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

Add Answer

## Stats

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

Seen: 3,708 times

Last updated: May 02 '15