This snippet shows how to find the complex roots of a polynomial using python (tested with python 2.6). You need the scipy or numpy module.
Find the Roots of a Polynomial.
TrustyTony commented: Nice collection of libraries +13
from numpy import poly1d
P = poly1d([3.4, -5.22, 2, 1, -7.1], variable = 'x')
print("Here is a polynomial\n")
print(P)
print("\nIts complex roots as a numpy array:")
print(P.r)
print("\nIts complex roots as a python list:")
print(list(P.r))
"""my output -->
Here is a polynomial
4 3 2
3.4 x - 5.22 x + 2 x + 1 x - 7.1
Its complex roots as a numpy array:
[ 1.57667814+0.j 0.43601402+1.12245146j 0.43601402-1.12245146j
-0.91341205+0.j ]
Its complex roots as a python list:
[(1.5766781395927345+0j), (0.43601401578206267+1.1224514554841667j), (0.43601401578206267-1.1224514554841667j), (-0.91341205350980392+0j)]
"""
Gribouillis 1,391 Programming Explorer Team Colleague
Gribouillis 1,391 Programming Explorer Team Colleague
Gribouillis 1,391 Programming Explorer Team Colleague
Gribouillis 1,391 Programming Explorer Team Colleague
Gribouillis 1,391 Programming Explorer Team Colleague
Gribouillis 1,391 Programming Explorer Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.