Class LaguerreSolver
java.lang.Object
org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver<PolynomialFunction>
org.apache.commons.math3.analysis.solvers.AbstractPolynomialSolver
org.apache.commons.math3.analysis.solvers.LaguerreSolver
- All Implemented Interfaces:
BaseUnivariateSolver<PolynomialFunction>
,PolynomialSolver
Implements the
Laguerre's Method for root finding of real coefficient polynomials.
For reference, see
A First Course in Numerical Analysis, ISBN 048641454X, chapter 8.Laguerre's method is global in the sense that it can start with any initial approximation and be able to solve all roots from that point. The algorithm requires a bracketing condition.
- Since:
- 1.2
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a solver with default accuracy (1e-6).LaguerreSolver
(double absoluteAccuracy) Construct a solver.LaguerreSolver
(double relativeAccuracy, double absoluteAccuracy) Construct a solver.LaguerreSolver
(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy) Construct a solver. -
Method Summary
Modifier and TypeMethodDescriptiondouble
doSolve()
Method for implementing actual optimization algorithms in derived classes.double
laguerre
(double lo, double hi, double fLo, double fHi) Deprecated.This method should not be part of the public API: It will be made private in version 4.0.Complex[]
solveAllComplex
(double[] coefficients, double initial) Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.Complex[]
solveAllComplex
(double[] coefficients, double initial, int maxEval) Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.solveComplex
(double[] coefficients, double initial) Find a complex root for the polynomial with the given coefficients, starting from the given initial value.solveComplex
(double[] coefficients, double initial, int maxEval) Find a complex root for the polynomial with the given coefficients, starting from the given initial value.Methods inherited from class org.apache.commons.math3.analysis.solvers.AbstractPolynomialSolver
getCoefficients, setup
Methods inherited from class org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver
computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getFunctionValueAccuracy, getMax, getMaxEvaluations, getMin, getRelativeAccuracy, getStartValue, incrementEvaluationCount, isBracketing, isSequence, solve, solve, solve, verifyBracketing, verifyInterval, verifySequence
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver
getAbsoluteAccuracy, getEvaluations, getFunctionValueAccuracy, getMaxEvaluations, getRelativeAccuracy, solve, solve, solve
-
Constructor Details
-
LaguerreSolver
public LaguerreSolver()Construct a solver with default accuracy (1e-6). -
LaguerreSolver
public LaguerreSolver(double absoluteAccuracy) Construct a solver.- Parameters:
absoluteAccuracy
- Absolute accuracy.
-
LaguerreSolver
public LaguerreSolver(double relativeAccuracy, double absoluteAccuracy) Construct a solver.- Parameters:
relativeAccuracy
- Relative accuracy.absoluteAccuracy
- Absolute accuracy.
-
LaguerreSolver
public LaguerreSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy) Construct a solver.- Parameters:
relativeAccuracy
- Relative accuracy.absoluteAccuracy
- Absolute accuracy.functionValueAccuracy
- Function value accuracy.
-
-
Method Details
-
doSolve
public double doSolve() throws TooManyEvaluationsException, NumberIsTooLargeException, NoBracketingExceptionMethod for implementing actual optimization algorithms in derived classes.- Specified by:
doSolve
in classBaseAbstractUnivariateSolver<PolynomialFunction>
- Returns:
- the root.
- Throws:
TooManyEvaluationsException
- if the maximal number of evaluations is exceeded.NoBracketingException
- if the initial search interval does not bracket a root and the solver requires it.NumberIsTooLargeException
-
laguerre
Deprecated.This method should not be part of the public API: It will be made private in version 4.0.Find a real root in the given interval. Despite the bracketing condition, the root returned byLaguerreSolver.ComplexSolver.solve(Complex[],Complex)
may not be a real zero inside[min, max]
. For example,p(x) = x3 + 1,
withmin = -2
,max = 2
,initial = 0
. When it occurs, this code callsLaguerreSolver.ComplexSolver.solveAll(Complex[],Complex)
in order to obtain all roots and picks up one real root.- Parameters:
lo
- Lower bound of the search interval.hi
- Higher bound of the search interval.fLo
- Function value at the lower bound of the search interval.fHi
- Function value at the higher bound of the search interval.- Returns:
- the point at which the function value is zero.
-
solveAllComplex
public Complex[] solveAllComplex(double[] coefficients, double initial) throws NullArgumentException, NoDataException, TooManyEvaluationsException Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.Note: This method is not part of the API of
BaseUnivariateSolver
.- Parameters:
coefficients
- Polynomial coefficients.initial
- Start value.- Returns:
- the full set of complex roots of the polynomial
- Throws:
TooManyEvaluationsException
- if the maximum number of evaluations is exceeded when solving for one of the rootsNullArgumentException
- if thecoefficients
isnull
.NoDataException
- if thecoefficients
array is empty.- Since:
- 3.1
-
solveAllComplex
public Complex[] solveAllComplex(double[] coefficients, double initial, int maxEval) throws NullArgumentException, NoDataException, TooManyEvaluationsException Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.Note: This method is not part of the API of
BaseUnivariateSolver
.- Parameters:
coefficients
- polynomial coefficientsinitial
- start valuemaxEval
- maximum number of evaluations- Returns:
- the full set of complex roots of the polynomial
- Throws:
TooManyEvaluationsException
- if the maximum number of evaluations is exceeded when solving for one of the rootsNullArgumentException
- if thecoefficients
isnull
NoDataException
- if thecoefficients
array is empty- Since:
- 3.5
-
solveComplex
public Complex solveComplex(double[] coefficients, double initial) throws NullArgumentException, NoDataException, TooManyEvaluationsException Find a complex root for the polynomial with the given coefficients, starting from the given initial value.Note: This method is not part of the API of
BaseUnivariateSolver
.- Parameters:
coefficients
- Polynomial coefficients.initial
- Start value.- Returns:
- a complex root of the polynomial
- Throws:
TooManyEvaluationsException
- if the maximum number of evaluations is exceeded.NullArgumentException
- if thecoefficients
isnull
.NoDataException
- if thecoefficients
array is empty.- Since:
- 3.1
-
solveComplex
public Complex solveComplex(double[] coefficients, double initial, int maxEval) throws NullArgumentException, NoDataException, TooManyEvaluationsException Find a complex root for the polynomial with the given coefficients, starting from the given initial value.Note: This method is not part of the API of
BaseUnivariateSolver
.- Parameters:
coefficients
- polynomial coefficientsinitial
- start valuemaxEval
- maximum number of evaluations- Returns:
- a complex root of the polynomial
- Throws:
TooManyEvaluationsException
- if the maximum number of evaluations is exceededNullArgumentException
- if thecoefficients
isnull
NoDataException
- if thecoefficients
array is empty- Since:
- 3.1
-