In [1]:
import numpy as np
import sympy as sym
from IPython.display import display,Math
In [2]:
# 3x^2 + 2x -1 = 0 == 3x^2 + 2x^1 -1x^0 = 0

coefs = [3,2,-1]

roots = np.roots(coefs)
roots
Out[2]:
array([-1.        ,  0.33333333])
In [3]:
x = sym.symbols('x')

pn = 3*x**2 + 2*x -1

for i in roots:
    display(Math('\\text{At }x=%g, \\quad %s = %g' %(i,sym.latex(pn),pn.subs(x,i))))
$\displaystyle \text{At }x=-1, \quad 3 x^{2} + 2 x - 1 = 0$
$\displaystyle \text{At }x=0.333333, \quad 3 x^{2} + 2 x - 1 = -3.33067e-16$
In [4]:
for i in range(1,11):
    coefs = np.arange(1,i+1)
    #print(coefs)
    print('A degree-%s polynomial has %s roots' %(len(coefs)-1,len(np.roots(coefs))))
A degree-0 polynomial has 0 roots
A degree-1 polynomial has 1 roots
A degree-2 polynomial has 2 roots
A degree-3 polynomial has 3 roots
A degree-4 polynomial has 4 roots
A degree-5 polynomial has 5 roots
A degree-6 polynomial has 6 roots
A degree-7 polynomial has 7 roots
A degree-8 polynomial has 8 roots
A degree-9 polynomial has 9 roots