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, NewtonSolver, SecantSolver

public abstract class UnivariateRealSolverImpl
extends Object
implements UnivariateRealSolver, Serializable

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

Version:
$Revision: 1.15 $ $Date: 2004/07/17 21:19:39 $
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.
(package private) static long serialVersionUID
          Serializable version identifier
 
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.
protected  boolean isBracketing(double lower, double upper, UnivariateRealFunction f)
          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 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.
protected  void verifyBracketing(double lower, double upper, UnivariateRealFunction f)
          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 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

serialVersionUID

static final long serialVersionUID
Serializable version identifier

See Also:
Constant Field Values

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 absolute error
defaultMaximalIterationCount - maximum number of iterations
Throws:
IllegalArgumentException - if f is null or the defaultAbsoluteAccuracy is not valid
Method Detail

getResult

public double getResult()
Access the last computed root.

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

getIterationCount

public int getIterationCount()
Access the last iteration count.

Specified by:
getIterationCount in interface UnivariateRealSolver
Returns:
the last iteration count
Throws:
IllegalStateException - 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)
Set the absolute accuracy.

Specified by:
setAbsoluteAccuracy in interface UnivariateRealSolver
Parameters:
accuracy - the accuracy.
Throws:
IllegalArgumentException - 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)
Set the relative accuracy.

Specified by:
setRelativeAccuracy in interface UnivariateRealSolver
Parameters:
accuracy - the relative accuracy.
Throws:
IllegalArgumentException - 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)
Set the function value accuracy.

Specified by:
setFunctionValueAccuracy in interface UnivariateRealSolver
Parameters:
accuracy - the accuracy.
Throws:
IllegalArgumentException - 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

isBracketing

protected boolean isBracketing(double lower,
                               double upper,
                               UnivariateRealFunction f)
                        throws FunctionEvaluationException
Returns true iff the function takes opposite signs at the endpoints.

Parameters:
lower - the lower endpoint
upper - the upper endpoint
f - 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:
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:
IllegalArgumentException

verifyBracketing

protected void verifyBracketing(double lower,
                                double upper,
                                UnivariateRealFunction f)
                         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
f - function
Throws:
IllegalArgumentException
FunctionEvaluationException - if an error occurs evaluating the function at the endpoints


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