usually a difficult task is to create an nth-order polynomial and find the roots with numpy:
import numpy
f = numpy.poly1d([1,2,3])
print numpy.roots(f)
array([-1.+1.41421356j, -1.-1.41421356j])
However, suppose you need a polynomial like:
f(x) = a*(x-x0)**0 + b(x-x0)**1 + ... + n(x-x0)**n
Is there an easy way to build the numpy.poly1d function and find the roots? I tried scipy.fsolve, but it is very unstable, since it strongly depends on the choice of starting values in my particular case.
Thanks in advance Regards rrrak
EDIT: Changed "polygon" (wrong) to "polynomial" (correct)
rrrak source
share