Search code examples
pythonwolfram-mathematica

Solving polynomial equations


Up to now I have always Mathematica for solving analytical equations. Now however I need to solve a few hundred equations of this type (characteristic polynomials)

a_20*x^20+a_19*x^19+...+a_1*x+a_0=0 (constant floats a_0,...a_20)

at once which yields awfully long calculation times in Mathematica.

Is there like a ready to use command in numpy or any other package to solve an equation of this type? (up to now I have used Python only for simulations so I don't know much about analytical tools and I couldn't find anything useful in the numpy tutorials).


Solution

  • You use numpy (apparently), but I've never tried it myself though: http://docs.scipy.org/doc/numpy/reference/generated/numpy.roots.html#numpy.roots.

    Numpy also provides a polynomial class... numpy.poly1d.

    This finds the roots numerically -- if you want the analytical roots, I don't think numpy can do that for you.