org.apache.commons.math.analysis.solvers
Class LaguerreSolver

java.lang.Object
  extended by org.apache.commons.math.ConvergingAlgorithmImpl
      extended by org.apache.commons.math.analysis.solvers.UnivariateRealSolverImpl
          extended by org.apache.commons.math.analysis.solvers.LaguerreSolver
All Implemented Interfaces:
UnivariateRealSolver, ConvergingAlgorithm

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: 922708 $ $Date: 2010-03-13 20:15:47 -0500 (Sat, 13 Mar 2010) $

Field Summary
private static java.lang.String NON_POLYNOMIAL_FUNCTION_MESSAGE
          Message for non-polynomial function.
private static java.lang.String NON_POSITIVE_DEGREE_MESSAGE
          Message for non-positive degree.
private  PolynomialFunction p
          Deprecated. as of 2.0 the function is not stored anymore in the instance
 
Fields inherited from class org.apache.commons.math.analysis.solvers.UnivariateRealSolverImpl
defaultFunctionValueAccuracy, f, functionValue, functionValueAccuracy, result, resultComputed
 
Fields inherited from class org.apache.commons.math.ConvergingAlgorithmImpl
absoluteAccuracy, defaultAbsoluteAccuracy, defaultMaximalIterationCount, defaultRelativeAccuracy, iterationCount, maximalIterationCount, relativeAccuracy
 
Constructor Summary
LaguerreSolver()
          Construct a solver.
LaguerreSolver(UnivariateRealFunction f)
          Deprecated. as of 2.0 the function to solve is passed as an argument to the solve(UnivariateRealFunction, double, double) or UnivariateRealSolver.solve(UnivariateRealFunction, double, double, double) method.
 
Method Summary
 PolynomialFunction getPolynomialFunction()
          Deprecated. as of 2.0 the function is not stored anymore within the instance.
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)
          Deprecated. 
 double solve(double min, double max, double initial)
          Deprecated. 
 double solve(UnivariateRealFunction f, double min, double max)
          Find a real root in the given interval.
 double solve(UnivariateRealFunction f, 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.solvers.UnivariateRealSolverImpl
checkResultComputed, clearResult, getFunctionValue, getFunctionValueAccuracy, getResult, isBracketing, isSequence, resetFunctionValueAccuracy, setFunctionValueAccuracy, setResult, setResult, verifyBracketing, verifyInterval, verifySequence
 
Methods inherited from class org.apache.commons.math.ConvergingAlgorithmImpl
getAbsoluteAccuracy, getIterationCount, getMaximalIterationCount, getRelativeAccuracy, resetAbsoluteAccuracy, resetMaximalIterationCount, resetRelativeAccuracy, setAbsoluteAccuracy, setMaximalIterationCount, setRelativeAccuracy
 
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.math.ConvergingAlgorithm
getAbsoluteAccuracy, getIterationCount, getMaximalIterationCount, getRelativeAccuracy, resetAbsoluteAccuracy, resetMaximalIterationCount, resetRelativeAccuracy, setAbsoluteAccuracy, setMaximalIterationCount, setRelativeAccuracy
 

Field Detail

NON_POLYNOMIAL_FUNCTION_MESSAGE

private static final java.lang.String NON_POLYNOMIAL_FUNCTION_MESSAGE
Message for non-polynomial function.

See Also:
Constant Field Values

NON_POSITIVE_DEGREE_MESSAGE

private static final java.lang.String NON_POSITIVE_DEGREE_MESSAGE
Message for non-positive degree.

See Also:
Constant Field Values

p

@Deprecated
private final PolynomialFunction p
Deprecated. as of 2.0 the function is not stored anymore in the instance
polynomial function to solve.

Constructor Detail

LaguerreSolver

@Deprecated
public LaguerreSolver(UnivariateRealFunction f)
               throws java.lang.IllegalArgumentException
Deprecated. as of 2.0 the function to solve is passed as an argument to the solve(UnivariateRealFunction, double, double) or UnivariateRealSolver.solve(UnivariateRealFunction, double, double, double) method.

Construct a solver for the given function.

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

LaguerreSolver

public LaguerreSolver()
Construct a solver.

Method Detail

getPolynomialFunction

@Deprecated
public PolynomialFunction getPolynomialFunction()
Deprecated. as of 2.0 the function is not stored anymore within the instance.

Returns a copy of the polynomial function.

Returns:
a fresh copy of the polynomial function

solve

@Deprecated
public double solve(double min,
                               double max)
             throws ConvergenceException,
                    FunctionEvaluationException
Deprecated. 

Solve for a zero root in the given interval.

A solver may require that the interval brackets a single zero root. Solvers that do require bracketing should be able to handle the case where one of the endpoints is itself a root.

Parameters:
min - the lower bound for the interval.
max - the upper bound for the interval.
Returns:
a value where the function 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

solve

@Deprecated
public double solve(double min,
                               double max,
                               double initial)
             throws ConvergenceException,
                    FunctionEvaluationException
Deprecated. 

Solve for a zero in the given interval, start at startValue.

A solver may require that the interval brackets a single zero root. Solvers that do require bracketing should be able to handle the case where one of the endpoints is itself a root.

Parameters:
min - the lower bound for the interval.
max - the upper bound for the interval.
initial - the start value to use
Returns:
a value where the function 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

solve

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

Requires bracketing condition.

Parameters:
f - function to solve (must be polynomial)
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(UnivariateRealFunction f,
                    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:
f - the function to solve
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


Copyright (c) 2003-2010 Apache Software Foundation