## org.apache.commons.math.analysis.solvers
Class UnivariateRealSolverImpl

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

All Implemented Interfaces:
  UnivariateRealSolver, ConvergingAlgorithm

Direct Known Subclasses:
  BisectionSolver, BrentSolver, LaguerreSolver, MullerSolver, NewtonSolver, RiddersSolver, SecantSolver

    public abstract class UnivariateRealSolverImpl

extends ConvergingAlgorithmImpl
implements UnivariateRealSolver

Provide a default implementation for several functions useful to generic solvers.

Version:
  $Revision: 811833 $ $Date: 2009-09-06 12:27:50 -0400 (Sun, 06 Sep 2009) $

Field Summary
`protected double` `defaultFunctionValueAccuracy` Default maximum error of function.
`protected UnivariateRealFunction` `f` Deprecated. as of 2.0 the function to solve is passed as an argument to the `UnivariateRealSolver.solve(UnivariateRealFunction, double, double)` or `UnivariateRealSolver.solve(UnivariateRealFunction, double, double, double)` method.
`protected double` `functionValue` Value of the function at the last computed result.
`protected double` `functionValueAccuracy` Maximum error of function.
`protected double` `result` The last computed root.
`protected boolean` `resultComputed` Indicates where a root has been computed.

Fields inherited from class org.apache.commons.math.ConvergingAlgorithmImpl
`absoluteAccuracy, defaultAbsoluteAccuracy, defaultMaximalIterationCount, defaultRelativeAccuracy, iterationCount, maximalIterationCount, relativeAccuracy`

Constructor Summary
`protected` `UnivariateRealSolverImpl(int defaultMaximalIterationCount, double defaultAbsoluteAccuracy)` Construct a solver with given iteration count and accuracy.
`protected` `UnivariateRealSolverImpl(UnivariateRealFunction f, int defaultMaximalIterationCount, double defaultAbsoluteAccuracy)` Deprecated. as of 2.0 the function to solve is passed as an argument to the `UnivariateRealSolver.solve(UnivariateRealFunction, double, double)` or `UnivariateRealSolver.solve(UnivariateRealFunction, double, double, double)` method.

Method Summary
`protected void` `checkResultComputed()` Check if a result has been computed.
`protected void` `clearResult()` Convenience function for implementations.
`double` `getFunctionValue()` Get the result of the last run of the solver.
`double` `getFunctionValueAccuracy()` Get the actual function value accuracy.
`double` `getResult()` Get the result of the last run of the solver.
`protected boolean` `isBracketing(double lower, double upper, UnivariateRealFunction function)` Returns true iff the function takes opposite signs at the endpoints.
`protected boolean` `isSequence(double start, double mid, double end)` Returns true if the arguments form a (strictly) increasing sequence
`void` `resetFunctionValueAccuracy()` Reset the actual function accuracy to the default.
`void` `setFunctionValueAccuracy(double accuracy)` Set the function value accuracy.
`protected void` `setResult(double x, double fx, int iterationCount)` Convenience function for implementations.
`protected void` `setResult(double newResult, int iterationCount)` Convenience function for implementations.
`protected void` `verifyBracketing(double lower, double upper, UnivariateRealFunction function)` Verifies that the endpoints specify an interval and the function takes opposite signs at the enpoints, throws IllegalArgumentException if not
`protected void` `verifyInterval(double lower, double upper)` Verifies that the endpoints specify an interval, throws IllegalArgumentException if not
`protected void` `verifySequence(double lower, double initial, double upper)` Verifies that `lower < initial < upper` throws IllegalArgumentException if not

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.analysis.solvers.UnivariateRealSolver
`solve, solve, solve, solve`

Methods inherited from interface org.apache.commons.math.ConvergingAlgorithm
`getAbsoluteAccuracy, getIterationCount, getMaximalIterationCount, getRelativeAccuracy, resetAbsoluteAccuracy, resetMaximalIterationCount, resetRelativeAccuracy, setAbsoluteAccuracy, setMaximalIterationCount, setRelativeAccuracy`

Field Detail

### functionValueAccuracy

    protected double functionValueAccuracy

  Maximum error of function.

### defaultFunctionValueAccuracy

    protected double defaultFunctionValueAccuracy

  Default maximum error of function.

### resultComputed

    protected boolean resultComputed

  Indicates where a root has been computed.

### result

    protected double result

  The last computed root.

### functionValue

    protected double functionValue

  Value of the function at the last computed result.

### f

    @Deprecated
    protected UnivariateRealFunction f

  Deprecated. as of 2.0 the function to solve is passed as an argument to the `UnivariateRealSolver.solve(UnivariateRealFunction, double, double)` or `UnivariateRealSolver.solve(UnivariateRealFunction, double, double, double)` method.
  The function to solve.

Constructor Detail

### UnivariateRealSolverImpl

    @Deprecated
    protected UnivariateRealSolverImpl(UnivariateRealFunction f,
                                                  int defaultMaximalIterationCount,
                                                  double defaultAbsoluteAccuracy)

  Deprecated. as of 2.0 the function to solve is passed as an argument to the `UnivariateRealSolver.solve(UnivariateRealFunction, double, double)` or `UnivariateRealSolver.solve(UnivariateRealFunction, double, double, double)` method.

  Construct a solver with given iteration count and accuracy.

  Parameters:
    `f` - the function to solve.
    `defaultAbsoluteAccuracy` - maximum absolute error
    `defaultMaximalIterationCount` - maximum number of iterations
  Throws:
    `java.lang.IllegalArgumentException` - if f is null or the defaultAbsoluteAccuracy is not valid

### UnivariateRealSolverImpl

    protected UnivariateRealSolverImpl(int defaultMaximalIterationCount,
                                       double defaultAbsoluteAccuracy)

  Construct a solver with given iteration count and accuracy.

  Parameters:
    `defaultAbsoluteAccuracy` - maximum absolute error
    `defaultMaximalIterationCount` - maximum number of iterations
  Throws:
    `java.lang.IllegalArgumentException` - if f is null or the defaultAbsoluteAccuracy is not valid

Method Detail

### checkResultComputed

    protected void checkResultComputed()
                                throws java.lang.IllegalStateException

  Check if a result has been computed.

  Throws:
    `java.lang.IllegalStateException` - if no result has been computed

### getResult

    public double getResult()

  Get the result of the last run of the solver.

  Specified by:
    `getResult` in interface `UnivariateRealSolver`
  Returns:
    the last result.

### getFunctionValue

    public double getFunctionValue()

  Get the result of the last run of the solver.

  Specified by:
    `getFunctionValue` in interface `UnivariateRealSolver`
  Returns:
    the value of the function at the last result.

### setFunctionValueAccuracy

    public void setFunctionValueAccuracy(double accuracy)

  Set the function value accuracy.

  This is used to determine when an evaluated function value or some other value which is used as divisor is zero.

  This is a safety guard and it shouldn't be necessary to change this in general.

  Specified by:
    `setFunctionValueAccuracy` in interface `UnivariateRealSolver`
  Parameters:
    `accuracy` - the accuracy.

### getFunctionValueAccuracy

    public double getFunctionValueAccuracy()

  Get the actual function value accuracy.

  Specified by:
    `getFunctionValueAccuracy` in interface `UnivariateRealSolver`
  Returns:
    the accuracy

### resetFunctionValueAccuracy

    public void resetFunctionValueAccuracy()

  Reset the actual function accuracy to the default. The default value is provided by the solver implementation.

  Specified by:
    `resetFunctionValueAccuracy` in interface `UnivariateRealSolver`

### setResult

    protected final void setResult(double newResult,
                                   int iterationCount)

  Convenience function for implementations.

  Parameters:
    `newResult` - the result to set
    `iterationCount` - the iteration count to set

### setResult

    protected final void setResult(double x,
                                   double fx,
                                   int iterationCount)

  Convenience function for implementations.

  Parameters:
    `x` - the result to set
    `fx` - the result to set
    `iterationCount` - the iteration count to set

### clearResult

    protected final void clearResult()

  Convenience function for implementations.

### isBracketing

    protected boolean isBracketing(double lower,
                                   double upper,
                                   UnivariateRealFunction function)
                            throws FunctionEvaluationException

  Returns true iff the function takes opposite signs at the endpoints.

  Parameters:
    `lower` - the lower endpoint
    `upper` - the upper endpoint
    `function` - the function
  Returns:
    true if f(lower) * f(upper) < 0
  Throws:
    `FunctionEvaluationException` - if an error occurs evaluating the function at the endpoints

### isSequence

    protected boolean isSequence(double start,
                                 double mid,
                                 double end)

  Returns true if the arguments form a (strictly) increasing sequence

  Parameters:
    `start` - first number
    `mid` - second number
    `end` - third number
  Returns:
    true if the arguments form an increasing sequence

### verifyInterval

    protected void verifyInterval(double lower,
                                  double upper)

  Verifies that the endpoints specify an interval, throws IllegalArgumentException if not

  Parameters:
    `lower` - lower endpoint
    `upper` - upper endpoint
  Throws:
    `java.lang.IllegalArgumentException`

### verifySequence

    protected void verifySequence(double lower,
                                  double initial,
                                  double upper)

  Verifies that `lower < initial < upper` throws IllegalArgumentException if not

  Parameters:
    `lower` - lower endpoint
    `initial` - initial value
    `upper` - upper endpoint
  Throws:
    `java.lang.IllegalArgumentException`

### verifyBracketing

    protected void verifyBracketing(double lower,
                                    double upper,
                                    UnivariateRealFunction function)
                             throws FunctionEvaluationException

  Verifies that the endpoints specify an interval and the function takes opposite signs at the enpoints, throws IllegalArgumentException if not

  Parameters:
    `lower` - lower endpoint
    `upper` - upper endpoint
    `function` - function
  Throws:
    `java.lang.IllegalArgumentException`
    `FunctionEvaluationException` - if an error occurs evaluating the function at the endpoints

Copyright (c) 2003-2011 Apache Software Foundation