org.apache.commons.math.analysis
Class LaguerreSolver

java.lang.Object
  extended by org.apache.commons.math.analysis.UnivariateRealSolverImpl
      extended by org.apache.commons.math.analysis.LaguerreSolver
All Implemented Interfaces:
java.io.Serializable, UnivariateRealSolver

public class LaguerreSolver
extends UnivariateRealSolverImpl

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.

Since:
1.2
Version:
$Revision: 620312 $ $Date: 2008-02-10 12:28:59 -0700 (Sun, 10 Feb 2008) $
See Also:
Serialized Form

Field Summary
private  PolynomialFunction p
          polynomial function to solve
private static long serialVersionUID
          serializable version identifier
 
Fields inherited from class org.apache.commons.math.analysis.UnivariateRealSolverImpl
absoluteAccuracy, defaultAbsoluteAccuracy, defaultFunctionValueAccuracy, defaultMaximalIterationCount, defaultRelativeAccuracy, f, functionValueAccuracy, iterationCount, maximalIterationCount, relativeAccuracy, result, resultComputed
 
Constructor Summary
LaguerreSolver(UnivariateRealFunction f)
          Construct a solver for the given function.
 
Method Summary
 PolynomialFunction getPolynomialFunction()
          Returns a copy of the polynomial function.
protected  boolean isRootOK(double min, double max, Complex z)
          Returns true iff the given complex root is actually a real zero in the given interval, within the solver tolerance level.
 Complex solve(Complex[] coefficients, Complex initial)
          Find a complex root for the polynomial with the given coefficients, starting from the given initial value.
 double solve(double min, double max)
          Find a real root in the given interval.
 double solve(double min, double max, double initial)
          Find a real root in the given interval with initial value.
 Complex[] solveAll(Complex[] coefficients, Complex initial)
          Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.
 Complex[] solveAll(double[] coefficients, double initial)
          Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.
 
Methods inherited from class org.apache.commons.math.analysis.UnivariateRealSolverImpl
clearResult, getAbsoluteAccuracy, getFunctionValueAccuracy, getIterationCount, getMaximalIterationCount, getRelativeAccuracy, getResult, isBracketing, isSequence, resetAbsoluteAccuracy, resetFunctionValueAccuracy, resetMaximalIterationCount, resetRelativeAccuracy, setAbsoluteAccuracy, setFunctionValueAccuracy, setMaximalIterationCount, setRelativeAccuracy, setResult, verifyBracketing, verifyInterval, verifySequence
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
serializable version identifier

See Also:
Constant Field Values

p

private PolynomialFunction p
polynomial function to solve

Constructor Detail

LaguerreSolver

public LaguerreSolver(UnivariateRealFunction f)
               throws java.lang.IllegalArgumentException
Construct a solver for the given function.

Parameters:
f - function to solve
Throws:
java.lang.IllegalArgumentException - if function is not polynomial
Method Detail

getPolynomialFunction

public PolynomialFunction getPolynomialFunction()
Returns a copy of the polynomial function.

Returns:
a fresh copy of the polynomial function

solve

public double solve(double min,
                    double max,
                    double initial)
             throws ConvergenceException,
                    FunctionEvaluationException
Find a real root in the given interval with initial value.

Requires bracketing condition.

Parameters:
min - the lower bound for the interval
max - the upper bound for the interval
initial - the start value to use
Returns:
the point at which the function value is zero
Throws:
ConvergenceException - if the maximum iteration count is exceeded or the solver detects convergence problems otherwise
FunctionEvaluationException - if an error occurs evaluating the function
java.lang.IllegalArgumentException - if any parameters are invalid

solve

public double solve(double min,
                    double max)
             throws ConvergenceException,
                    FunctionEvaluationException
Find a real root in the given interval.

Despite the bracketing condition, the root returned by solve(Complex[], Complex) may not be a real zero inside [min, max]. For example, p(x) = x^3 + 1, min = -2, max = 2, initial = 0. We can either try another initial value, or, as we did here, call solveAll() to obtain all roots and pick up the one that we're looking for.

Parameters:
min - the lower bound for the interval
max - the upper bound for the interval
Returns:
the point at which the function value is zero
Throws:
ConvergenceException - if the maximum iteration count is exceeded or the solver detects convergence problems otherwise
FunctionEvaluationException - if an error occurs evaluating the function
java.lang.IllegalArgumentException - if any parameters are invalid

isRootOK

protected boolean isRootOK(double min,
                           double max,
                           Complex z)
Returns true iff the given complex root is actually a real zero in the given interval, within the solver tolerance level.

Parameters:
min - the lower bound for the interval
max - the upper bound for the interval
z - the complex root
Returns:
true iff z is the sought-after real zero

solveAll

public Complex[] solveAll(double[] coefficients,
                          double initial)
                   throws ConvergenceException,
                          FunctionEvaluationException
Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.

Parameters:
coefficients - the polynomial coefficients array
initial - the start value to use
Returns:
the point at which the function value is zero
Throws:
ConvergenceException - if the maximum iteration count is exceeded or the solver detects convergence problems otherwise
FunctionEvaluationException - if an error occurs evaluating the function
java.lang.IllegalArgumentException - if any parameters are invalid

solveAll

public Complex[] solveAll(Complex[] coefficients,
                          Complex initial)
                   throws MaxIterationsExceededException,
                          FunctionEvaluationException
Find all complex roots for the polynomial with the given coefficients, starting from the given initial value.

Parameters:
coefficients - the polynomial coefficients array
initial - the start value to use
Returns:
the point at which the function value is zero
Throws:
MaxIterationsExceededException - if the maximum iteration count is exceeded or the solver detects convergence problems otherwise
FunctionEvaluationException - if an error occurs evaluating the function
java.lang.IllegalArgumentException - if any parameters are invalid

solve

public Complex solve(Complex[] coefficients,
                     Complex initial)
              throws MaxIterationsExceededException,
                     FunctionEvaluationException
Find a complex root for the polynomial with the given coefficients, starting from the given initial value.

Parameters:
coefficients - the polynomial coefficients array
initial - the start value to use
Returns:
the point at which the function value is zero
Throws:
MaxIterationsExceededException - if the maximum iteration count is exceeded or the solver detects convergence problems otherwise
FunctionEvaluationException - if an error occurs evaluating the function
java.lang.IllegalArgumentException - if any parameters are invalid