The fastest way to solve a long polynomial with many different abilities

I am looking for a quick solution x for this polynomial equation:

Let m be an element from the set M.

sum over all m {a_m * x ^ (b_m) - c_m * x ^ (b_m - 1)} = 0, where a_m, b_m, c_m are all different for each m. The set M has ~ 15-20 elements.

If the solution is> 4, it will return 4. If the solution is <0, it will return 0. What is the fastest way to do this? Perform it numerically?

I would prefer a solution in python and other languages ​​only if it is very useful for switching.

Note that this is a derivative of the objective function. I'm just trying to maximize the objective function, so if there is a better way to do it aside from solving this polynomial, it will work too! The solution should be pretty quick as I try to solve many of these objective functions.

+4
source share
1 answer

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.

+2
source

Source: https://habr.com/ru/post/1385002/


All Articles