from sympy import symbols, Poly, solve from sympy.plotting import plot
Define the function f and the variable x
x = symbols('x') f = x5 - 13x3 - x2 + 10x + 170
Convert f to a polynomial
f_poly = Poly(f, x)
Find all the roots
roots = solve(f_poly, domain='CC')
Print all roots
print("All roots:") for root in roots: root_approx = root.evalf() print(root_approx)
Filter real and complex roots
real_roots = [root for root in roots if root.is_real] complex_roots = [root for root in roots if not root.is_real]
Print real roots
print("Real roots:") for root in real_roots: root_approx = root.evalf() print(root_approx)
Print complex roots
print("Complex roots:") for root in complex_roots: root_approx = root.evalf() print(root_approx)
Print the number of real roots
num_real_roots = len(real_roots) print("Number of real roots:", num_real_roots)
Plot the real part of the function f
p1 = plot(f, (x, -5, 5), title='Graph of f(x)', real=True) help for Gerschgorin-Circle