1
I’m having a hard time with a university job and I’ve come to ask for your help here.
I have two lists of candidate values to be roots of a polynomial.
listaDivisoresP = []
for i in range(int(p[0])):
if p[0]%(i+1) == 0:
listaDivisoresP.append(i+1)
print(listaDivisoresP)
listaDivisoresN = []
for i in range (len(listaDivisoresP)):
listaDivisoresN.append(-listaDivisoresP[i])
print(listaDivisoresN)
As the code shows, I have a list of the values of the positive candidates and another one of the values of the negative candidates. Now, I wanted to take a polynomial that has its coefficients given by a list. For example, the polynomial:
5x^4+3x^3-2x^2+x-2
You have your list (p) indicated by:
p[] = {5, 3, -2, 1, 2}
With this polynomial, I want to test all the values that are in the lists to find out which result value is zero. When you find a value that results in zero, I want to create a new list (listRaizesInteiras) with the values that zero the polynomial. For that, I tried the following:
listaRaizInteira = []
listaTesteRaizes = []
for i in range(len(listaDivisoresP) - 1):
contador = len (p) - 1
while contador > 0:
raiz = (listaDivisoresP[i]**(contador)) * p[contador]
listaTesteRaizes.append(raiz)
contador = contador - 1
if sum(listaTesteRaizes) + p[0] == 0:
listaRaizInteira.append(listaDivisoresP[i])
However, I’m not getting the list I want. In this case, I only tested for the positive values (using the Software list), because with the negative values (from the Software list) it would be quite similar.
Someone can help me do what I’m trying to do?
Thanks for the help!
– CodingNewbie