Package org.hipparchus.analysis.solvers
Class BracketingNthOrderBrentSolver
- java.lang.Object
-
- org.hipparchus.analysis.solvers.BaseAbstractUnivariateSolver<UnivariateFunction>
-
- org.hipparchus.analysis.solvers.AbstractUnivariateSolver
-
- org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver
-
- All Implemented Interfaces:
BaseUnivariateSolver<UnivariateFunction>
,BracketedUnivariateSolver<UnivariateFunction>
,UnivariateSolver
public class BracketingNthOrderBrentSolver extends AbstractUnivariateSolver implements BracketedUnivariateSolver<UnivariateFunction>
This class implements a modification of the Brent algorithm.The changes with respect to the original Brent algorithm are:
- the returned value is chosen in the current interval according
to user specified
AllowedSolution
, - the maximal order for the invert polynomial root search is user-specified instead of being invert quadratic only
The given interval must bracket the root.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.hipparchus.analysis.solvers.BracketedUnivariateSolver
BracketedUnivariateSolver.Interval
-
-
Constructor Summary
Constructors Constructor Description BracketingNthOrderBrentSolver()
Construct a solver with default accuracy and maximal order (1e-6 and 5 respectively)BracketingNthOrderBrentSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy, int maximalOrder)
Construct a solver.BracketingNthOrderBrentSolver(double relativeAccuracy, double absoluteAccuracy, int maximalOrder)
Construct a solver.BracketingNthOrderBrentSolver(double absoluteAccuracy, int maximalOrder)
Construct a solver.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double
doSolve()
Method for implementing actual optimization algorithms in derived classes.protected BracketedUnivariateSolver.Interval
doSolveInterval()
Find a root and return the containing interval.int
getMaximalOrder()
Get the maximal order.double
solve(int maxEval, UnivariateFunction f, double min, double max, double startValue, AllowedSolution allowedSolution)
Solve for a zero in the given interval, start atstartValue
.double
solve(int maxEval, UnivariateFunction f, double min, double max, AllowedSolution allowedSolution)
Solve for a zero in the given interval.BracketedUnivariateSolver.Interval
solveInterval(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, getMaxEvaluations, getMin, getRelativeAccuracy, getStartValue, incrementEvaluationCount, isBracketing, isSequence, setup, solve, 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, getMaxEvaluations, getRelativeAccuracy, solve, solve, solve
-
Methods inherited from interface org.hipparchus.analysis.solvers.BracketedUnivariateSolver
solveInterval
-
-
-
-
Constructor Detail
-
BracketingNthOrderBrentSolver
public BracketingNthOrderBrentSolver()
Construct a solver with default accuracy and maximal order (1e-6 and 5 respectively)
-
BracketingNthOrderBrentSolver
public BracketingNthOrderBrentSolver(double absoluteAccuracy, int maximalOrder) throws MathIllegalArgumentException
Construct a solver.- Parameters:
absoluteAccuracy
- Absolute accuracy.maximalOrder
- maximal order.- Throws:
MathIllegalArgumentException
- if maximal order is lower than 2
-
BracketingNthOrderBrentSolver
public BracketingNthOrderBrentSolver(double relativeAccuracy, double absoluteAccuracy, int maximalOrder) throws MathIllegalArgumentException
Construct a solver.- Parameters:
relativeAccuracy
- Relative accuracy.absoluteAccuracy
- Absolute accuracy.maximalOrder
- maximal order.- Throws:
MathIllegalArgumentException
- if maximal order is lower than 2
-
BracketingNthOrderBrentSolver
public BracketingNthOrderBrentSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy, int maximalOrder) throws MathIllegalArgumentException
Construct a solver.- Parameters:
relativeAccuracy
- Relative accuracy.absoluteAccuracy
- Absolute accuracy.functionValueAccuracy
- Function value accuracy.maximalOrder
- maximal order.- Throws:
MathIllegalArgumentException
- if maximal order is lower than 2
-
-
Method Detail
-
getMaximalOrder
public int getMaximalOrder()
Get the maximal order.- Returns:
- maximal order
-
doSolve
protected double doSolve()
Method for implementing actual optimization algorithms in derived classes.- Specified by:
doSolve
in classBaseAbstractUnivariateSolver<UnivariateFunction>
- Returns:
- the root.
-
doSolveInterval
protected BracketedUnivariateSolver.Interval doSolveInterval()
Find a root and return the containing interval.- Returns:
- an interval containing the root such that both end points meet the convergence criteria.
-
solve
public double solve(int maxEval, UnivariateFunction f, double min, double max, AllowedSolution allowedSolution) throws MathIllegalArgumentException, MathIllegalStateException
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:
solve
in 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.
- Throws:
MathIllegalArgumentException
- if the arguments do not satisfy the requirements specified by the solver.MathIllegalStateException
- if the allowed number of evaluations is exceeded.
-
solve
public double solve(int maxEval, UnivariateFunction f, double min, double max, double startValue, AllowedSolution allowedSolution) throws MathIllegalArgumentException, MathIllegalStateException
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:
solve
in 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.
- Throws:
MathIllegalArgumentException
- if the arguments do not satisfy the requirements specified by the solver.MathIllegalStateException
- if the allowed number of evaluations is exceeded.
-
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:
solveInterval
in 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 | <=
absolute
accuracy + max(ta, tb) *relative
accuracy) 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.
-
-