org.apache.commons.math.analysis
Class SecantSolver

java.lang.Object
  extended by org.apache.commons.math.analysis.UnivariateRealSolverImpl
      extended by org.apache.commons.math.analysis.SecantSolver
All Implemented Interfaces:
java.io.Serializable, UnivariateRealSolver

public class SecantSolver
extends UnivariateRealSolverImpl
implements java.io.Serializable

Implements a modified version of the secant method for approximating a zero of a real univariate function.

The algorithm is modified to maintain bracketing of a root by successive approximations. Because of forced bracketing, convergence may be slower than the unrestricted secant algorithm. However, this implementation should in general outperform the regula falsi method.

The function is assumed to be continuous but not necessarily smooth.

Version:
$Revision: 615734 $ $Date: 2008-01-27 23:10:03 -0700 (Sun, 27 Jan 2008) $
See Also:
Serialized Form

Field Summary
private static long serialVersionUID
          Serializable version identifier
 
Fields inherited from class org.apache.commons.math.analysis.UnivariateRealSolverImpl
absoluteAccuracy, defaultAbsoluteAccuracy, defaultFunctionValueAccuracy, defaultMaximalIterationCount, defaultRelativeAccuracy, f, functionValueAccuracy, iterationCount, maximalIterationCount, relativeAccuracy, result, resultComputed
 
Constructor Summary
SecantSolver(UnivariateRealFunction f)
          Construct a solver for the given function.
 
Method Summary
 double solve(double min, double max)
          Find a zero in the given interval.
 double solve(double min, double max, double initial)
          Find a zero in the given interval.
 
Methods inherited from class org.apache.commons.math.analysis.UnivariateRealSolverImpl
clearResult, getAbsoluteAccuracy, getFunctionValueAccuracy, getIterationCount, getMaximalIterationCount, getRelativeAccuracy, getResult, isBracketing, isSequence, resetAbsoluteAccuracy, resetFunctionValueAccuracy, resetMaximalIterationCount, resetRelativeAccuracy, setAbsoluteAccuracy, setFunctionValueAccuracy, setMaximalIterationCount, setRelativeAccuracy, setResult, verifyBracketing, verifyInterval, verifySequence
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serializable version identifier

See Also:
Constant Field Values
Constructor Detail

SecantSolver

public SecantSolver(UnivariateRealFunction f)
Construct a solver for the given function.

Parameters:
f - function to solve.
Method Detail

solve

public double solve(double min,
                    double max,
                    double initial)
             throws MaxIterationsExceededException,
                    FunctionEvaluationException
Find a zero in the given interval.

Specified by:
solve in interface UnivariateRealSolver
Parameters:
min - the lower bound for the interval
max - the upper bound for the interval
initial - the start value to use (ignored)
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
java.lang.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(double min,
                    double max)
             throws MaxIterationsExceededException,
                    FunctionEvaluationException
Find a zero in the given interval.

Specified by:
solve in interface UnivariateRealSolver
Parameters:
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
java.lang.IllegalArgumentException - if min is not less than max or the signs of the values of the function at the endpoints are not opposites