Class PolynomialSolver

• java.lang.Object
• org.robwork.sdurw_math.PolynomialSolver

• public class PolynomialSolver
extends java.lang.Object
Find solutions for roots of real and complex polynomial equations.

The solutions are found analytically if the polynomial is of maximum order 3.
For polynomials of order 4 and higher, Laguerre's Method is used to find
roots until the polynomial can be deflated to order 3.
The remaining roots will then be found analytically.

Some Polynomials are particularly easy to solve. A polynomial of the form
a x^n + b = 0
will be solved by taking the n'th roots of -\frac{b}{a} directly, giving n distinct
roots in the complex plane.

To illustrate the procedure, consider the equation:
10^{-15} x^8 - 10^{-15} x^7 + x^7 + 2 x^6 - x^4 - 2x^3 + 10^{-15} x= 0

The solver will use the following procedure (here with the precision \epsilon = 10^{-14}):

1. Remove terms that are small compared to \epsilon: x^7 + 2 x^6 - x^4 - 2x^3 = 0

2. Find zero roots and reduce the order: There is a triple root in x = 0 and the remaining
polynomial becomes: x^4 + 2 x^3 - x - 2 = 0.

3. Use Laguerre to find a root of x^4 + 2 x^3 - x - 2 = 0

Depending on the initial guess for Laguerre, different roots might be found first.
The algorithm will proceed differently depending on the found root:

1. If root x=-2 is found, remaining polynomial after deflation is x^3 -1 = 0.
The roots are found directly as the cubic root of 1, which is three distinct roots in the
complex plane (one is on the real axis).

2. If root x=1 is found, remaining polynomial after deflation is x^3 + 3 x^2 +3 x + 2 = 0. The roots are found analytically, giving one real root x=-2 and two complex conjugate
roots x = -0.5 \pm \frac{\sqrt{3}}{2} i.

3. If other roots than x=1 or x=-2 is found (a complex root), remaining polynomial is a third
order polynomial with complex coefficients. This polynomial is solved analytically to give
remaining two real roots, and one remaining complex root.

Notice that cases 2+3 requires analytical solution of the third order polynomial equation.
For higher order polynomials Laguerre would need to be used to find the next root.
In this case it is particularly lucky to hit case 1, as this gives the solutions right away
no matter what order the remaining polynomial is.
• Constructor Summary

Constructors
Constructor Description
PolynomialSolver​(long cPtr, boolean cMemoryOwn)
PolynomialSolver​(SWIGTYPE_p_rw__math__PolynomialT_double_t polynomial)
Create a solver for a polynomial with real coefficients.
PolynomialSolver​(SWIGTYPE_p_rw__math__PolynomialT_std__complexT_double_t_t polynomial)
Create a solver for a polynomial with complex coefficients.
• Method Summary

All Methods
Modifier and Type Method Description
void delete()
static long getCPtr​(PolynomialSolver obj)
vector_d getRealSolutions()
vector_d getRealSolutions​(double epsilon)
VectorComplexDouble getSolutions()
VectorComplexDouble getSolutions​(double epsilon)
void setInitialGuess()
Use a specific initial guess for a root.
void setInitialGuess​(complexd guess)
Use a specific initial guess for a root.
void setLaguerreIterations()
Set the number of iterations to take in the Laguerre method.
void setLaguerreIterations​(long iterations)
Set the number of iterations to take in the Laguerre method.
• Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• Constructor Detail

• PolynomialSolver

public PolynomialSolver​(long cPtr,
boolean cMemoryOwn)
• PolynomialSolver

public PolynomialSolver​(SWIGTYPE_p_rw__math__PolynomialT_double_t polynomial)
Create a solver for a polynomial with real coefficients.
Parameters:
polynomial - [in] the polynomial to find roots for.
• PolynomialSolver

public PolynomialSolver​(SWIGTYPE_p_rw__math__PolynomialT_std__complexT_double_t_t polynomial)
Create a solver for a polynomial with complex coefficients.
Parameters:
polynomial - [in] the polynomial to find roots for.
• Method Detail

• getCPtr

public static long getCPtr​(PolynomialSolver obj)
• delete

public void delete()
• setInitialGuess

public void setInitialGuess​(complexd guess)
Use a specific initial guess for a root.
Parameters:
guess - [in] a complex initial guess for the algorithm.
• setInitialGuess

public void setInitialGuess()
Use a specific initial guess for a root.
• getRealSolutions

public vector_d getRealSolutions​(double epsilon)
• getRealSolutions

public vector_d getRealSolutions()
• getSolutions

public VectorComplexDouble getSolutions​(double epsilon)
• getSolutions

public VectorComplexDouble getSolutions()
• setLaguerreIterations

public void setLaguerreIterations​(long iterations)
Set the number of iterations to take in the Laguerre method.
Parameters:
iterations - [in] the maximum number of iterations (default is 10).
• setLaguerreIterations

public void setLaguerreIterations()
Set the number of iterations to take in the Laguerre method.