# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.function.polynomial.root

## Class PolyRoot

• java.lang.Object
• com.numericalmethod.suanshu.analysis.function.polynomial.root.PolyRoot
• All Implemented Interfaces:
PolyRootSolver

public class PolyRoot
extends Object
implements PolyRootSolver
This is a solver for finding the roots of a polynomial equation. A root (or a zero) of a polynomial p is a member x in the domain of p such that p(x) vanishes. That is, p(x) = 0. By the fundamental theorem of algebra, every polynomial of degree n has n roots. The roots can be both real (double) or Complex. The Abel-Ruffini theorem says that we have analytical solution for polynomials of degree up to 4.

This implementation solves a polynomial of degree 1 by LinearRoot, degree 2 by QuadraticRoot, degree 3 by CubicRoot, degree 4 by QuarticRoot, and others by the Jenkins-Traub algorithm JenkinsTraubReal.

• ### Constructor Summary

Constructors
Constructor and Description
PolyRoot()
• ### Method Summary

All Methods
Modifier and Type Method and Description
static List<Complex> getComplexRoots(List<? extends Number> roots)
Get a copy of only the Complex but not real roots of a polynomial.
static List<Double> getRealRoots(List<? extends Number> roots)
Get a copy of only the real roots of a polynomial.
List<? extends Number> solve(Polynomial polynomial)
Get the roots/zeros of a polynomial.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### PolyRoot

public PolyRoot()
• ### Method Detail

• #### solve

public List<? extends Number> solve(Polynomial polynomial)
Get the roots/zeros of a polynomial.
Specified by:
solve in interface PolyRootSolver
Parameters:
polynomial - the polynomial to be solved
Returns:
the roots of the polynomial
Throws:
IllegalArgumentException - if the polynomial is a constant, hence no solution
• #### getRealRoots

public static List<Double> getRealRoots(List<? extends Number> roots)
Get a copy of only the real roots of a polynomial. The union of these and getComplexRoots(java.util.List) are all the roots.
Parameters:
roots - all the roots of a polynomial
Returns:
a copy of the real roots