Roots of polynomials

The application was created to solve the problem of calculating the real roots of a given polynomial in a unique way

Description

The command line application accepts polynomial coefficients and a precision parameter, calculating the polynomial's real zeros.

Code description

Command line Java application.

The concept of this algorithm involves the following steps:

  • Identify the regions where the derivative function equals zero. This can be achieved by calculating the zeros of the derivative
  • Apply the Bolzano theorem within each of those regions to locate the zeros of the original polynomial

However, there's a catch-22: We must first compute the zeros of the derivative function in order to define the zeros of the polynomial itself!

Solution: We apply recursion until we reach a polynomial that allows easy calculation of its zeros. This process can be repeated until we derive an affine function


Disadvantages:

  • If the degree of the polynomial (n) is large, the derivation can yield very high numbers (like n!), which may complicate calculations.
  • The complexity of the operations will depend on the size of the numbers, which can be represented as a function of log(n!)

For realistic degrees found in real life, there should be no problem


The algorithm has been designed without assuming any floating-point data, utilizing Java generics instead

The application supports the use of Double or BigDecimal, but a Float version could easily be implemented

It is a proof of concept. Programming it for BigDecimal alone would have sufficed, but using generics makes the algorithms cooler and more illustrative for beginners


I haven't extensively tested the application yet, and there's a possibility it could be fine-tuned to improve accuracy and functionality in more scenarios. However, I believe the code has great potential.

I think it can be effectively adjusted to work in all scenarios.

Windows

All

Polynomial Roots (2023)

Download

Versions

image

Polynomial root calculators are a staple in the field of computer science careers.

I contribute my version of the solution to the problem.

It is not a very efficient solution since the computational complexity in the worst case is O(G^2), where G represents the polynomial degree

However, I think it gets the job done effectively


The algorithm is based on calculating the roots of a polynomial, assuming that the roots of its derivative function are known

Under this assumption, it is straightforward to calculate the roots because we can determine the range limit of the roots (See: Properties of the polynomial roots)

In this manner, we can determine the range of each potential root by using the derivative function roots, and we can compute the zeros by applying Bolzano's theorem.

But ... we need the function to calculate the roots of the derivative function!

No problem. We use recursion to compute the roots of a polynomial. The recursive function has a termination case for the scenario of a polynomial of degree zero (a constant), which we assume has no roots.

Since the derivative function has one degree less than the original polynomial, by using recursion, we can calculate the roots of a polynomial at zero degrees, making it a simple problem to solve


This way of proceeding may require precision in our calculations, but that is not a problem if we use the Java BigDecimal class.

Downloads