org.apache.commons.math.analysis.solvers

## Class BrentSolver

- java.lang.Object
- - org.apache.commons.math.ConvergingAlgorithmImpl
  - - org.apache.commons.math.analysis.solvers.UnivariateRealSolverImpl
    - - org.apache.commons.math.analysis.solvers.BrentSolver

- All Implemented Interfaces:
    UnivariateRealSolver, ConvergingAlgorithm

      public class BrentSolver
      extends UnivariateRealSolverImpl

  Implements the Brent algorithm for finding zeros of real univariate functions.

  The function should be continuous but not necessarily smooth.

  Version:
    $Revision:670469 $ $Date:2008-06-23 10:01:38 +0200 (lun., 23 juin 2008) $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static double` | `DEFAULT_ABSOLUTE_ACCURACY` Default absolute accuracy
    `static int` | `DEFAULT_MAXIMUM_ITERATIONS` Default maximum number of iterations
    `private static long` | `serialVersionUID` Serializable version identifier

    - ### 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

    Constructors
    Constructor and Description
    `BrentSolver()` Deprecated. in 2.2 (to be removed in 3.0).
    `BrentSolver(double absoluteAccuracy)` Construct a solver with the given absolute accuracy.
    `BrentSolver(int maximumIterations, double absoluteAccuracy)` Contstruct a solver with the given maximum iterations and absolute accuracy.
    `BrentSolver(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

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `double` | `solve(double min, double max)` Deprecated.
    `double` | `solve(double min, double max, double initial)` Deprecated.
    `double` | `solve(int maxEval, UnivariateRealFunction f, double min, double max)` Find a zero in the given interval.
    `double` | `solve(int maxEval, UnivariateRealFunction f, double min, double max, double initial)` Find a zero in the given interval with an initial guess.
    `double` | `solve(UnivariateRealFunction f, double min, double max)` Deprecated. in 2.2 (to be removed in 3.0).
    `double` | `solve(UnivariateRealFunction f, double min, double max, double initial)` Deprecated. in 2.2 (to be removed in 3.0).
    `private double` | `solve(UnivariateRealFunction f, double x0, double y0, double x1, double y1, double x2, double y2)` Find a zero starting search according to the three provided points.

    - ### 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, incrementIterationsCounter, resetAbsoluteAccuracy, resetIterationsCounter, 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

    - #### DEFAULT_ABSOLUTE_ACCURACY

          public static final double DEFAULT_ABSOLUTE_ACCURACY

      Default absolute accuracy
      Since:
        2.1
      See Also:
        Constant Field Values

    - #### DEFAULT_MAXIMUM_ITERATIONS

          public static final int DEFAULT_MAXIMUM_ITERATIONS

      Default maximum number of iterations
      Since:
        2.1
      See Also:
        Constant Field Values

    - #### serialVersionUID

          private static final long serialVersionUID

      Serializable version identifier
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### BrentSolver

          @Deprecated
          public BrentSolver(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.
      Construct a solver for the given function.
      Parameters:
        `f` - function to solve.

    - #### BrentSolver

          @Deprecated
          public BrentSolver()

      Deprecated. in 2.2 (to be removed in 3.0).
      Construct a solver with default properties.

    - #### BrentSolver

          public BrentSolver(double absoluteAccuracy)

      Construct a solver with the given absolute accuracy.
      Parameters:
        `absoluteAccuracy` - lower bound for absolute accuracy of solutions returned by the solver
      Since:
        2.1

    - #### BrentSolver

          public BrentSolver(int maximumIterations,
                     double absoluteAccuracy)

      Contstruct a solver with the given maximum iterations and absolute accuracy.
      Parameters:
        `maximumIterations` - maximum number of iterations
        `absoluteAccuracy` - lower bound for absolute accuracy of solutions returned by the solver
      Since:
        2.1

  - ### Method Detail

    - #### solve

          @Deprecated
          public double solve(double min,
                                double max)
                       throws MaxIterationsExceededException,
                              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:
        `FunctionEvaluationException` - if an error occurs evaluating the function
        `MaxIterationsExceededException`

    - #### solve

          @Deprecated
          public double solve(double min,
                                double max,
                                double initial)
                       throws MaxIterationsExceededException,
                              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:
        `FunctionEvaluationException` - if an error occurs evaluating the function
        `MaxIterationsExceededException`

    - #### solve

          @Deprecated
          public double solve(UnivariateRealFunction f,
                                double min,
                                double max,
                                double initial)
                       throws MaxIterationsExceededException,
                              FunctionEvaluationException

      Deprecated. in 2.2 (to be removed in 3.0).
      Find a zero in the given interval with an initial guess.

      Throws `IllegalArgumentException` if the values of the function at the three points have the same sign (note that it is allowed to have endpoints with the same sign if the initial point has opposite sign function-wise).

      Parameters:
        `f` - function to solve.
        `min` - the lower bound for the interval.
        `max` - the upper bound for the interval.
        `initial` - the start value to use (must be set to min if no initial point is known).
      Returns:
        the value where the function is zero
      Throws:
        `MaxIterationsExceededException` - the maximum iteration count is exceeded
        `FunctionEvaluationException` - if an error occurs evaluating the function
        `IllegalArgumentException` - if initial is not between min and max (even if it is a root)

    - #### solve

          public double solve(int maxEval,
                     UnivariateRealFunction f,
                     double min,
                     double max,
                     double initial)
                       throws MaxIterationsExceededException,
                              FunctionEvaluationException

      Find a zero in the given interval with an initial guess.

      Throws `IllegalArgumentException` if the values of the function at the three points have the same sign (note that it is allowed to have endpoints with the same sign if the initial point has opposite sign function-wise).

      Overrides:
        `solve` in class `UnivariateRealSolverImpl`
      Parameters:
        `f` - function to solve.
        `min` - the lower bound for the interval.
        `max` - the upper bound for the interval.
        `initial` - the start value to use (must be set to min if no initial point is known).
        `maxEval` - Maximum number of evaluations.
      Returns:
        the value where the function is zero
      Throws:
        `MaxIterationsExceededException` - the maximum iteration count is exceeded
        `FunctionEvaluationException` - if an error occurs evaluating the function
        `IllegalArgumentException` - if initial is not between min and max (even if it is a root)

    - #### solve

          @Deprecated
          public double solve(UnivariateRealFunction f,
                                double min,
                                double max)
                       throws MaxIterationsExceededException,
                              FunctionEvaluationException

      Deprecated. in 2.2 (to be removed in 3.0).
      Find a zero in the given interval.

      Requires that the values of the function at the endpoints have opposite signs. An `IllegalArgumentException` is thrown if this is not the case.

      Parameters:
        `f` - the function to solve
        `min` - the lower bound for the interval.
        `max` - the upper bound for the interval.
      Returns:
        the value where the function is zero
      Throws:
        `MaxIterationsExceededException` - if the maximum iteration count is exceeded
        `FunctionEvaluationException` - if an error occurs evaluating the function
        `IllegalArgumentException` - if min is not less than max or the signs of the values of the function at the endpoints are not opposites

    - #### solve

          public double solve(int maxEval,
                     UnivariateRealFunction f,
                     double min,
                     double max)
                       throws MaxIterationsExceededException,
                              FunctionEvaluationException

      Find a zero in the given interval.

      Requires that the values of the function at the endpoints have opposite signs. An `IllegalArgumentException` is thrown if this is not the case.

      Overrides:
        `solve` in class `UnivariateRealSolverImpl`
      Parameters:
        `f` - the function to solve
        `min` - the lower bound for the interval.
        `max` - the upper bound for the interval.
        `maxEval` - Maximum number of evaluations.
      Returns:
        the value where the function is zero
      Throws:
        `MaxIterationsExceededException` - if the maximum iteration count is exceeded
        `FunctionEvaluationException` - if an error occurs evaluating the function
        `IllegalArgumentException` - if min is not less than max or the signs of the values of the function at the endpoints are not opposites

    - #### solve

          private double solve(UnivariateRealFunction f,
                     double x0,
                     double y0,
                     double x1,
                     double y1,
                     double x2,
                     double y2)
                        throws MaxIterationsExceededException,
                               FunctionEvaluationException

      Find a zero starting search according to the three provided points.
      Parameters:
        `f` - the function to solve
        `x0` - old approximation for the root
        `y0` - function value at the approximation for the root
        `x1` - last calculated approximation for the root
        `y1` - function value at the last calculated approximation for the root
        `x2` - bracket point (must be set to x0 if no bracket point is known, this will force starting with linear interpolation)
        `y2` - function value at the bracket point.
      Returns:
        the value where the function is zero
      Throws:
        `MaxIterationsExceededException` - if the maximum iteration count is exceeded
        `FunctionEvaluationException` - if an error occurs evaluating the function

Copyright (c) 2003-2013 Apache Software Foundation