Top Description Inners Fields Constructors Methods
org.apache.commons.math3.analysis.solvers

public Class LaguerreSolver

extends AbstractPolynomialSolver
Class Inheritance
Imports
org.apache.commons.math3.analysis.polynomials.PolynomialFunction, org.apache.commons.math3.complex.Complex, .ComplexUtils, org.apache.commons.math3.exception.NoBracketingException, .NoDataException, .NullArgumentException, .NumberIsTooLargeException, .TooManyEvaluationsException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.util.FastMath

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
LaguerreSolver.ComplexSolver

Class for searching all (complex) roots.

Field Summary

Modifier and TypeField and Description
private final LaguerreSolver.ComplexSolver
complexSolver

Complex solver.

private static final double
DEFAULT_ABSOLUTE_ACCURACY

Default absolute accuracy.

Constructor Summary

AccessConstructor and Description
public
LaguerreSolver()

Construct a solver with default accuracy (1e-6).

public
LaguerreSolver(double
Absolute accuracy.
absoluteAccuracy
)

Construct a solver.

public
LaguerreSolver(double
Relative accuracy.
relativeAccuracy
,
double
Absolute accuracy.
absoluteAccuracy
)

Construct a solver.

public
LaguerreSolver(double
Relative accuracy.
relativeAccuracy
,
double
Absolute accuracy.
absoluteAccuracy
,
double
Function value accuracy.
functionValueAccuracy
)

Construct a solver.

Method Summary

Modifier and TypeMethod and Description
public double
doSolve()

Implements abstract org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.doSolve.

Method for implementing actual optimization algorithms in derived classes.

public double

Returns:

the point at which the function value is zero.
laguerre
(double
Lower bound of the search interval.
lo
,
double
Higher bound of the search interval.
hi
,
double
Function value at the lower bound of the search interval.
fLo
,
double
Function value at the higher bound of the search interval.
fHi
)
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.

public Complex[]

Returns:

the full set of complex roots of the polynomial
solveAllComplex
(double[]
Polynomial coefficients.
coefficients
,
double
Start value.
initial
)

Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.

public Complex[]

Returns:

the full set of complex roots of the polynomial
solveAllComplex
(double[]
polynomial coefficients
coefficients
,
double
start value
initial
,
int
maximum number of evaluations
maxEval
)

Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.

public Complex

Returns:

a complex root of the polynomial
solveComplex
(double[]
Polynomial coefficients.
coefficients
,
double
Start value.
initial
)

Find a complex root for the polynomial with the given coefficients, starting from the given initial value.

public Complex

Returns:

a complex root of the polynomial
solveComplex
(double[]
polynomial coefficients
coefficients
,
double
start value
initial
,
int
maximum number of evaluations
maxEval
)

Find a complex root for the polynomial with the given coefficients, starting from the given initial value.

Inherited from org.apache.commons.math3.analysis.solvers.AbstractPolynomialSolver:
getCoefficientssetup

Field Detail

complexSolverback to summary
private final LaguerreSolver.ComplexSolver complexSolver

Complex solver.

DEFAULT_ABSOLUTE_ACCURACYback to summary
private static final double DEFAULT_ABSOLUTE_ACCURACY

Default absolute accuracy.

Constructor Detail

LaguerreSolverback to summary
public LaguerreSolver()

Construct a solver with default accuracy (1e-6).

LaguerreSolverback to summary
public LaguerreSolver(double absoluteAccuracy)

Construct a solver.

Parameters
absoluteAccuracy:double

Absolute accuracy.

LaguerreSolverback to summary
public LaguerreSolver(double relativeAccuracy, double absoluteAccuracy)

Construct a solver.

Parameters
relativeAccuracy:double

Relative accuracy.

absoluteAccuracy:double

Absolute accuracy.

LaguerreSolverback to summary
public LaguerreSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy)

Construct a solver.

Parameters
relativeAccuracy:double

Relative accuracy.

absoluteAccuracy:double

Absolute accuracy.

functionValueAccuracy:double

Function value accuracy.

Method Detail

doSolveback to summary
public double doSolve() throws TooManyEvaluationsException, NumberIsTooLargeException, NoBracketingException

Implements abstract org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.doSolve.

Doc from org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.doSolve.

Method for implementing actual optimization algorithms in derived classes.

Returns:double

the root.

Annotations
@Override
Exceptions
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.
laguerreback to summary
public 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.

Find a real root in the given interval. Despite the bracketing condition, the root returned by LaguerreSolver.ComplexSolver#solve(Complex[], Complex) may not be a real zero inside [min, max]. For example, p(x) = x3 + 1, with min = -2, max = 2, initial = 0. When it occurs, this code calls LaguerreSolver.ComplexSolver#solveAll(Complex[], Complex) in order to obtain all roots and picks up one real root.

Parameters
lo:double

Lower bound of the search interval.

hi:double

Higher bound of the search interval.

fLo:double

Function value at the lower bound of the search interval.

fHi:double

Function value at the higher bound of the search interval.

Returns:double

the point at which the function value is zero.

Annotations
@Deprecated
solveAllComplexback to summary
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:double[]

Polynomial coefficients.

initial:double

Start value.

Returns:Complex[]

the full set of complex roots of the polynomial

Exceptions
NullArgumentException:
if the coefficients is null.
NoDataException:
if the coefficients array is empty.
TooManyEvaluationsException:
if the maximum number of evaluations is exceeded when solving for one of the roots
Since
3.1
solveAllComplexback to summary
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:double[]

polynomial coefficients

initial:double

start value

maxEval:int

maximum number of evaluations

Returns:Complex[]

the full set of complex roots of the polynomial

Exceptions
NullArgumentException:
if the coefficients is null
NoDataException:
if the coefficients array is empty
TooManyEvaluationsException:
if the maximum number of evaluations is exceeded when solving for one of the roots
Since
3.5
solveComplexback to summary
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:double[]

Polynomial coefficients.

initial:double

Start value.

Returns:Complex

a complex root of the polynomial

Exceptions
NullArgumentException:
if the coefficients is null.
NoDataException:
if the coefficients array is empty.
TooManyEvaluationsException:
if the maximum number of evaluations is exceeded.
Since
3.1
solveComplexback to summary
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:double[]

polynomial coefficients

initial:double

start value

maxEval:int

maximum number of evaluations

Returns:Complex

a complex root of the polynomial

Exceptions
NullArgumentException:
if the coefficients is null
NoDataException:
if the coefficients array is empty
TooManyEvaluationsException:
if the maximum number of evaluations is exceeded
Since
3.1
org.apache.commons.math3.analysis.solvers back to summary

private Class LaguerreSolver.ComplexSolver

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.analysis.solvers.LaguerreSolver.ComplexSolver

Class for searching all (complex) roots.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if z is a real zero.
isRoot
(double
Lower bound for the interval.
min
,
double
Upper bound for the interval.
max
,
Complex
Complex root.
z
)

Check whether the given complex root is actually a real zero in the given interval, within the solver tolerance level.

public Complex

Returns:

the point at which the function value is zero.
solve
(Complex[]
Polynomial coefficients.
coefficients
,
Complex
Start value.
initial
)

Find a complex root for the polynomial with the given coefficients, starting from the given initial value.

public Complex[]

Returns:

the point at which the function value is zero.
solveAll
(Complex[]
Polynomial coefficients.
coefficients
,
Complex
Start value.
initial
)

Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ComplexSolverback to summary
private ComplexSolver()

Method Detail

isRootback to summary
public boolean isRoot(double min, double max, Complex z)

Check whether the given complex root is actually a real zero in the given interval, within the solver tolerance level.

Parameters
min:double

Lower bound for the interval.

max:double

Upper bound for the interval.

z:Complex

Complex root.

Returns:boolean

true if z is a real zero.

solveback to summary
public Complex solve(Complex[] coefficients, Complex initial) throws NullArgumentException, NoDataException, TooManyEvaluationsException

Find a complex root for the polynomial with the given coefficients, starting from the given initial value.

Parameters
coefficients:Complex[]

Polynomial coefficients.

initial:Complex

Start value.

Returns:Complex

the point at which the function value is zero.

Exceptions
NullArgumentException:
if the coefficients is null.
NoDataException:
if the coefficients array is empty.
TooManyEvaluationsException:
if the maximum number of evaluations is exceeded.
solveAllback to summary
public Complex[] solveAll(Complex[] coefficients, Complex initial) throws NullArgumentException, NoDataException, TooManyEvaluationsException

Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.

Parameters
coefficients:Complex[]

Polynomial coefficients.

initial:Complex

Start value.

Returns:Complex[]

the point at which the function value is zero.

Exceptions
NullArgumentException:
if the coefficients is null.
NoDataException:
if the coefficients array is empty.
TooManyEvaluationsException:
if the maximum number of evaluations is exceeded.