Package org.hipparchus.analysis.solvers
Class BaseSecantSolver
- java.lang.Object
-
- org.hipparchus.analysis.solvers.BaseAbstractUnivariateSolver<UnivariateFunction>
-
- org.hipparchus.analysis.solvers.AbstractUnivariateSolver
-
- org.hipparchus.analysis.solvers.BaseSecantSolver
-
- All Implemented Interfaces:
BaseUnivariateSolver<UnivariateFunction>,BracketedUnivariateSolver<UnivariateFunction>,UnivariateSolver
- Direct Known Subclasses:
IllinoisSolver,PegasusSolver,RegulaFalsiSolver
public abstract class BaseSecantSolver extends AbstractUnivariateSolver implements BracketedUnivariateSolver<UnivariateFunction>
Base class for all bracketing Secant-based methods for root-finding (approximating a zero of a univariate real function).Implementation of the
Regula FalsiandIllinoismethods is based on the following article: M. Dowell and P. Jarratt, A modified regula falsi method for computing the root of an equation, BIT Numerical Mathematics, volume 11, number 2, pages 168-174, Springer, 1971.Implementation of the
Pegasusmethod is based on the following article: M. Dowell and P. Jarratt, The "Pegasus" method for computing the root of an equation, BIT Numerical Mathematics, volume 12, number 4, pages 503-508, Springer, 1972.The
Secantmethod is not a bracketing method, so it is not implemented here. It has a separate implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classBaseSecantSolver.MethodSecant-based root-finding methods.-
Nested classes/interfaces inherited from interface org.hipparchus.analysis.solvers.BracketedUnivariateSolver
BracketedUnivariateSolver.Interval
-
-
Field Summary
Fields Modifier and Type Field Description protected static doubleDEFAULT_ABSOLUTE_ACCURACYDefault absolute accuracy.
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseSecantSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy, BaseSecantSolver.Method method)Construct a solver.protectedBaseSecantSolver(double relativeAccuracy, double absoluteAccuracy, BaseSecantSolver.Method method)Construct a solver.protectedBaseSecantSolver(double absoluteAccuracy, BaseSecantSolver.Method method)Construct a solver.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected doubledoSolve()Method for implementing actual optimization algorithms in derived classes.protected BracketedUnivariateSolver.IntervaldoSolveInterval()Find a root and return the containing interval.doublesolve(int maxEval, UnivariateFunction f, double min, double max, double startValue)Solve for a zero in the given interval, start atstartValue.doublesolve(int maxEval, UnivariateFunction f, double min, double max, double startValue, AllowedSolution allowedSolution)Solve for a zero in the given interval, start atstartValue.doublesolve(int maxEval, UnivariateFunction f, double min, double max, AllowedSolution allowedSolution)Solve for a zero in the given interval.BracketedUnivariateSolver.IntervalsolveInterval(int maxEval, UnivariateFunction f, double min, double max, double startValue)Solve for a zero in the given interval and return a tolerance interval surrounding the root.-
Methods inherited from class org.hipparchus.analysis.solvers.BaseAbstractUnivariateSolver
computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getFunctionValueAccuracy, getMax, getMin, getRelativeAccuracy, getStartValue, incrementEvaluationCount, isBracketing, isSequence, setup, solve, solve, verifyBracketing, verifyInterval, verifySequence
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hipparchus.analysis.solvers.BaseUnivariateSolver
getAbsoluteAccuracy, getEvaluations, getFunctionValueAccuracy, getRelativeAccuracy, solve, solve
-
Methods inherited from interface org.hipparchus.analysis.solvers.BracketedUnivariateSolver
solveInterval
-
-
-
-
Field Detail
-
DEFAULT_ABSOLUTE_ACCURACY
protected static final double DEFAULT_ABSOLUTE_ACCURACY
Default absolute accuracy.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BaseSecantSolver
protected BaseSecantSolver(double absoluteAccuracy, BaseSecantSolver.Method method)Construct a solver.- Parameters:
absoluteAccuracy- Absolute accuracy.method- Secant-based root-finding method to use.
-
BaseSecantSolver
protected BaseSecantSolver(double relativeAccuracy, double absoluteAccuracy, BaseSecantSolver.Method method)Construct a solver.- Parameters:
relativeAccuracy- Relative accuracy.absoluteAccuracy- Absolute accuracy.method- Secant-based root-finding method to use.
-
BaseSecantSolver
protected BaseSecantSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy, BaseSecantSolver.Method method)Construct a solver.- Parameters:
relativeAccuracy- Maximum relative error.absoluteAccuracy- Maximum absolute error.functionValueAccuracy- Maximum function value error.method- Secant-based root-finding method to use
-
-
Method Detail
-
solve
public double solve(int maxEval, UnivariateFunction f, double min, double max, AllowedSolution allowedSolution)Solve for a zero 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.- Specified by:
solvein interfaceBracketedUnivariateSolver<UnivariateFunction>- Parameters:
maxEval- Maximum number of evaluations.f- Function to solve.min- Lower bound for the interval.max- Upper bound for the interval.allowedSolution- The kind of solutions that the root-finding algorithm may accept as solutions.- Returns:
- A value where the function is zero.
-
solve
public double solve(int maxEval, UnivariateFunction f, double min, double max, double startValue, AllowedSolution allowedSolution)Solve for a zero in the given interval, start atstartValue. 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.- Specified by:
solvein interfaceBracketedUnivariateSolver<UnivariateFunction>- Parameters:
maxEval- Maximum number of evaluations.f- Function to solve.min- Lower bound for the interval.max- Upper bound for the interval.startValue- Start value to use.allowedSolution- The kind of solutions that the root-finding algorithm may accept as solutions.- Returns:
- A value where the function is zero.
-
solve
public double solve(int maxEval, UnivariateFunction f, double min, double max, double startValue)Solve for a zero in the given interval, start atstartValue. 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.- Specified by:
solvein interfaceBaseUnivariateSolver<UnivariateFunction>- Overrides:
solvein classBaseAbstractUnivariateSolver<UnivariateFunction>- Parameters:
maxEval- Maximum number of evaluations.f- Function to solve.min- Lower bound for the interval.max- Upper bound for the interval.startValue- Start value to use.- Returns:
- a value where the function is zero.
-
solveInterval
public BracketedUnivariateSolver.Interval solveInterval(int maxEval, UnivariateFunction f, double min, double max, double startValue) throws MathIllegalArgumentException, MathIllegalStateException
Solve for a zero in the given interval and return a tolerance interval surrounding the root.It is required that the starting interval brackets a root or that the function value at either end point is 0.0.
- Specified by:
solveIntervalin interfaceBracketedUnivariateSolver<UnivariateFunction>- Parameters:
maxEval- Maximum number of evaluations.f- Function to solve.min- Lower bound for the interval.max- Upper bound for the interval. Must be greater thanmin.startValue- start value to use. Must be in the interval [min, max].- Returns:
- an interval [ta, tb] such that for some t in [ta, tb] f(t) == 0.0 or has a
step wise discontinuity that crosses zero. Both end points also satisfy the
convergence criteria so either one could be used as the root. That is the interval
satisfies the condition (| tb - ta | <=
absoluteaccuracy + max(ta, tb) *relativeaccuracy) or ( max(|f(ta)|, |f(tb)|) <=BaseUnivariateSolver.getFunctionValueAccuracy()) or there are no floating point numbers between ta and tb. The width of the interval (tb - ta) may be zero. - Throws:
MathIllegalArgumentException- if the arguments do not satisfy the requirements specified by the solver.MathIllegalStateException- if the allowed number of evaluations is exceeded.
-
doSolve
protected final double doSolve() throws MathIllegalStateExceptionMethod for implementing actual optimization algorithms in derived classes.- Specified by:
doSolvein classBaseAbstractUnivariateSolver<UnivariateFunction>- Returns:
- the root.
- Throws:
MathIllegalStateException- if the algorithm failed due to finite precision.
-
doSolveInterval
protected final BracketedUnivariateSolver.Interval doSolveInterval() throws MathIllegalStateException
Find a root and return the containing interval.- Returns:
- an interval containing the root such that the selected end point meets the convergence criteria.
- Throws:
MathIllegalStateException- if convergence fails.
-
-