If you are looking for only one root, and not all the roots, you can use the Newton Method , which I believe is fast enough for the polynomials that you described.
let f (x) = the sum over all m { a*x^(b) - c*x^(b-1)
}
then f '(x), the derivative of f (x), is the sum over all m { (a*b)*x^(b-1) - (c*(b-1))*x^(b-2)
}.
def newton(f, fprime, firstguess, epsilon): x = firstguess while abs(f(x)) > epsilon: x = x - (f(x) / fprime(x)) return x
This will return the approximate root to your polynomial. If it is not accurate enough, go to the smaller epsilon until it is accurate enough.
Please note that this function may diverge and work forever or throw a ZeroDivisionError. Handle with care.
source share