I have to write a function that takes a parameter p with the list representing the polynomial p(x) and returns the canonical list of the entire roots of p(x). For example, the polynomial with the coefficients [1, -5, 6] must return the roots [2, 3]. I must use lists and consider that the first coefficient will always be 1.
degree = int(input('degree: '))
p=[]
i=0
while i <= degree: #creates polynomial
coef = int(input("Coef: "))
p.append(coef)
i+=1
# creates p(possible roots)
pê=[0]
for x in range(1,p[-1]):
if b % x == 0:
pê.append(-x)
pê.append(x)
for g in pê:
You can use numpy for this.
import numpy as np
coeff=[1,-5,6]
roots=np.roots(coeff)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.