Class PolyRoot
- java.lang.Object
-
- dev.nm.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) orComplex. 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 byLinearRoot, degree 2 byQuadraticRoot, degree 3 byCubicRoot, degree 4 byQuarticRoot, and others by the Jenkins-Traub algorithmJenkinsTraubReal.
-
-
Constructor Summary
Constructors Constructor Description PolyRoot()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static List<Complex>getComplexRoots(List<? extends Number> roots)Get a copy of only theComplexbut 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.
-
-
-
Method Detail
-
solve
public List<? extends Number> solve(Polynomial polynomial)
Get the roots/zeros of a polynomial.- Specified by:
solvein interfacePolyRootSolver- 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 andgetComplexRoots(java.util.List)are all the roots.- Parameters:
roots- all the roots of a polynomial- Returns:
- a copy of the real roots
-
getComplexRoots
public static List<Complex> getComplexRoots(List<? extends Number> roots)
Get a copy of only theComplexbut not real roots of a polynomial. The union of these andgetRealRoots(java.util.List)are all the roots.- Parameters:
roots- all the roots of a polynomial- Returns:
- a copy of the
Complexroots
-
-