I’m trying to write a root-finding code using my polynomial function that performs multiplication of f(x) with f(-x), and doing a certain equation on its coefficients. Here is my code:

for i in range(1,5): for j, (prev_coeff, next_coeff) in enumerate(zip(non_zeros, non_zeros[1:])): x = ( abs(next_coeff) / abs(prev_coeff) ) ** ( (1/2)**(1) ) print ("x%d ="%(j+1) , "{:0.4f}". format(x)) set_roots.append("{:0.4f}". format(x)) pol = q_x print (set_roots)

Basically, I wanted to iterate it 5 times. However. I am encountering this error:

Traceback (most recent call last): File "<ipython-input-24-5af005f59724>", line 7, in <module> pol_nx = pol(-x) # f(-x) TypeError: 'numpy.ndarray' object is not callable

I think the error occurred to when I put pol = q_x since they are of different data types. Is there another way I could rewrite this such that I could loop the coefficients of q_x back to my pol? I want to use the coefficients of my q_x as the coefficients of my new polynomial, then do the same process again.

Thank you. I am very new to writing programming codes.

## Answer

The roots are already known and calculated in the background automatically, when the polynomial is created.

x = np.poly1d([1,0]) # Create an instance of a polynomial class for x p = x**3 - 3*x**2 + 5*x - 6 print(p.r)

You can gets roots very easy, another example:

roots = ((-1)**p.o*p(-x)*p(x)).r