org.apache.commons.math.analysis
Class UnivariateRealSolverImpl

java.lang.Object
  extended byorg.apache.commons.math.analysis.UnivariateRealSolverImpl
All Implemented Interfaces:
Serializable, UnivariateRealSolver
Direct Known Subclasses:
BisectionSolver, BrentSolver, SecantSolver

public abstract class UnivariateRealSolverImpl
extends Object
implements UnivariateRealSolver, Serializable

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

Version:
$Revision: 1.8 $ $Date: 2003/11/19 03:28:23 $
See Also:
Serialized Form

Field Summary
protected  double absoluteAccuracy
          Maximum absolute error.
protected  double defaultAbsoluteAccuracy
          Default maximum absolute error.
protected  double defaultFunctionValueAccuracy
          Default maximum error of function.
protected  int defaultMaximalIterationCount
          Default maximum number of iterations.
protected  double defaultRelativeAccuracy
          Default maximum relative error.
protected  UnivariateRealFunction f
          The function to solve.
protected  double functionValueAccuracy
          Maximum error of function.
protected  int iterationCount
          The last iteration count.
protected  int maximalIterationCount
          Maximum number of iterations.
protected  double relativeAccuracy
          Maximum relative error.
protected  double result
          The last computed root.
protected  boolean resultComputed
          Indicates where a root has been computed.
 
Constructor Summary
protected UnivariateRealSolverImpl(UnivariateRealFunction f, int defaultMaximalIterationCount, double defaultAbsoluteAccuracy)
          Construct a solver with given iteration count and accuracy.
 
Method Summary
protected  void clearResult()
          Convenience function for implementations.
 double getAbsoluteAccuracy()
          Get the actual absolute accuracy.
 double getFunctionValueAccuracy()
          Get the actual function value accuracy.
 int getIterationCount()
          Access the last iteration count.
 int getMaximalIterationCount()
          Get the upper limit for the number of iterations.
 double getRelativeAccuracy()
          Get the actual relative accuracy.
 double getResult()
          Access the last computed root.
 void resetAbsoluteAccuracy()
          Reset the absolute accuracy to the default.
 void resetFunctionValueAccuracy()
          Reset the actual function accuracy to the default.
 void resetMaximalIterationCount()
          Reset the upper limit for the number of iterations to the default.
 void resetRelativeAccuracy()
          Reset the relative accuracy to the default.
 void setAbsoluteAccuracy(double accuracy)
          Set the absolute accuracy.
 void setFunctionValueAccuracy(double accuracy)
          Set the function value accuracy.
 void setMaximalIterationCount(int count)
          Set the upper limit for the number of iterations.
 void setRelativeAccuracy(double accuracy)
          Set the relative accuracy.
protected  void setResult(double result, int iterationCount)
          Convenience function for implementations.
 
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.UnivariateRealSolver
solve, solve
 

Field Detail

absoluteAccuracy

protected double absoluteAccuracy
Maximum absolute error.


relativeAccuracy

protected double relativeAccuracy
Maximum relative error.


functionValueAccuracy

protected double functionValueAccuracy
Maximum error of function.


maximalIterationCount

protected int maximalIterationCount
Maximum number of iterations.


defaultAbsoluteAccuracy

protected double defaultAbsoluteAccuracy
Default maximum absolute error.


defaultRelativeAccuracy

protected double defaultRelativeAccuracy
Default maximum relative error.


defaultFunctionValueAccuracy

protected double defaultFunctionValueAccuracy
Default maximum error of function.


defaultMaximalIterationCount

protected int defaultMaximalIterationCount
Default maximum number of iterations.


resultComputed

protected boolean resultComputed
Indicates where a root has been computed.


result

protected double result
The last computed root.


iterationCount

protected int iterationCount
The last iteration count.


f

protected UnivariateRealFunction f
The function to solve.

Constructor Detail

UnivariateRealSolverImpl

protected UnivariateRealSolverImpl(UnivariateRealFunction f,
                                   int defaultMaximalIterationCount,
                                   double defaultAbsoluteAccuracy)
Construct a solver with given iteration count and accuracy.

Parameters:
f - the function to solve.
defaultAbsoluteAccuracy - maximum absolue error.
defaultMaximalIterationCount - maximum number of iterations.
Method Detail

getResult

public double getResult()
                 throws MathException
Access the last computed root.

Specified by:
getResult in interface UnivariateRealSolver
Returns:
the last computed root.
Throws:
MathException - if no root has been computed.

getIterationCount

public int getIterationCount()
                      throws MathException
Access the last iteration count.

Specified by:
getIterationCount in interface UnivariateRealSolver
Returns:
the last iteration count.
Throws:
MathException - if no root has been computed.

setResult

protected final void setResult(double result,
                               int iterationCount)
Convenience function for implementations.

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

clearResult

protected final void clearResult()
Convenience function for implementations.


setAbsoluteAccuracy

public void setAbsoluteAccuracy(double accuracy)
                         throws MathException
Set the absolute accuracy.

Specified by:
setAbsoluteAccuracy in interface UnivariateRealSolver
Parameters:
accuracy - the accuracy.
Throws:
MathException - if the accuracy can't be achieved by the solver or is otherwise deemed unreasonable.

getAbsoluteAccuracy

public double getAbsoluteAccuracy()
Get the actual absolute accuracy.

Specified by:
getAbsoluteAccuracy in interface UnivariateRealSolver
Returns:
the accuracy

resetAbsoluteAccuracy

public void resetAbsoluteAccuracy()
Reset the absolute accuracy to the default.

Specified by:
resetAbsoluteAccuracy in interface UnivariateRealSolver

setMaximalIterationCount

public void setMaximalIterationCount(int count)
Set the upper limit for the number of iterations.

Specified by:
setMaximalIterationCount in interface UnivariateRealSolver
Parameters:
count - maximum number of iterations

getMaximalIterationCount

public int getMaximalIterationCount()
Get the upper limit for the number of iterations.

Specified by:
getMaximalIterationCount in interface UnivariateRealSolver
Returns:
the actual upper limit

resetMaximalIterationCount

public void resetMaximalIterationCount()
Reset the upper limit for the number of iterations to the default.

Specified by:
resetMaximalIterationCount in interface UnivariateRealSolver
See Also:
UnivariateRealSolver.setMaximalIterationCount(int)

setRelativeAccuracy

public void setRelativeAccuracy(double accuracy)
                         throws MathException
Set the relative accuracy.

Specified by:
setRelativeAccuracy in interface UnivariateRealSolver
Parameters:
accuracy - the relative accuracy.
Throws:
MathException - if the accuracy can't be achieved by the solver or is otherwise deemed unreasonable.

getRelativeAccuracy

public double getRelativeAccuracy()
Get the actual relative accuracy.

Specified by:
getRelativeAccuracy in interface UnivariateRealSolver
Returns:
the accuracy

resetRelativeAccuracy

public void resetRelativeAccuracy()
Reset the relative accuracy to the default.

Specified by:
resetRelativeAccuracy in interface UnivariateRealSolver

setFunctionValueAccuracy

public void setFunctionValueAccuracy(double accuracy)
                              throws MathException
Set the function value accuracy.

Specified by:
setFunctionValueAccuracy in interface UnivariateRealSolver
Parameters:
accuracy - the accuracy.
Throws:
MathException - if the accuracy can't be achieved by the solver or is otherwise deemed unreasonable.

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.

Specified by:
resetFunctionValueAccuracy in interface UnivariateRealSolver


Copyright © 2003-2004 Apache Software Foundation. All Rights Reserved.