java.lang.Object
org.bzdev.math.RootFinder<P>
org.bzdev.math.RootFinder.Brent<P>
- Enclosing class:
- RootFinder<P>
RootFinder class using Brent's method.
The implementation is based on the
Wikipedia
article about Brent's method.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.math.RootFinder
RootFinder.Brent<P>, RootFinder.ConvergenceException, RootFinder.Halley<P>, RootFinder.Newton<P>
-
Field Summary
Fields inherited from class org.bzdev.math.RootFinder
maxLimit
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
ferror
(double x) The error in the value returned byfunction
(x).abstract double
function
(double x) The function f in the equation y = f(x, p).static RootFinder.Brent
Create a new instance of RootFinder.Brent using aRealValuedFunction
orRealValuedFunctOps
to provide the root finder's function.static RootFinder.Brent
Create a new instance of RootFinder.Brent using aRealValuedFunction
orRealValuedFunctOps
to provide the root finder's function, plus a second function to provide error values (this function will be used to implement the methodRootFinder.ferror(double)
).double
solve
(double y, double... initialArgs) Solve an equation.Methods inherited from class org.bzdev.math.RootFinder
findRoot, getEpsilon, getParameters, refineSolution, setEpsilon, setEpsilon, setLimit, setParameters, solveBezier, solveCubic, solveCubic, solvePolynomial, solvePolynomial, solvePolynomial, solveQuadratic, solveQuadratic, solveQuartic
-
Constructor Details
-
Brent
public Brent()Constructor. -
Brent
Constructor given parameters.- Parameters:
parameters
- the parameters
-
-
Method Details
-
function
public abstract double function(double x) The function f in the equation y = f(x, p). The function f(x, p) is used with x varied and with the parameters p constant.- Specified by:
function
in classRootFinder<P>
- Parameters:
x
- the argument of the function- Returns:
- the value of the function f
- See Also:
-
ferror
public double ferror(double x) The error in the value returned byfunction
(x). The default implementation returns the same value asRootFinder.getEpsilon()
when epsilon was set in absolute mode and the value offunction
(x) multiplied by epsilon when epsilon was set in relative mode. Callers are encouraged to override this method when feasible.- Specified by:
ferror
in classRootFinder<P>
- Parameters:
x
- the argument passed tofunction(double)
- Returns:
- the error for
function
(x)
-
solve
public double solve(double y, double... initialArgs) Solve an equation. Starting from an initial guess, findRoot returns the value of x that satisfies f(x, p) = y, where p represents the current parameters. The initial arguments must be two values of x such that f(x, p) - y will differ in sign.- Specified by:
solve
in classRootFinder<P>
- Parameters:
y
- the desired value of f(x, p)initialArgs
- two initial arguments giving the upper and lower values that bracket the root.- Returns:
- the value of x that satisfies f(x, p) = y
- Throws:
RootFinder.ConvergenceException
- the method failedMathException
- an error occurred calling the function f or one of its derivatives.
-
newInstance
Create a new instance of RootFinder.Brent using aRealValuedFunction
orRealValuedFunctOps
to provide the root finder's function.A
RealValuedFunction
'sRealValuedFunction.derivAt(double)
andRealValuedFunction.secondDerivAt(double)
do not have to be implemented as these are not used.- Parameters:
f
- a function- Returns:
- a new root finder
-
newInstance
Create a new instance of RootFinder.Brent using aRealValuedFunction
orRealValuedFunctOps
to provide the root finder's function, plus a second function to provide error values (this function will be used to implement the methodRootFinder.ferror(double)
).A
RealValuedFunction
'sRealValuedFunction.derivAt(double)
andRealValuedFunction.secondDerivAt(double)
do not have to be implemented as these are not used. The function provided as the second argument will be used to implement the methodRootFinder.ferror(double)
.- Parameters:
f
- a functionef
- a function providing the error for f(x)- Returns:
- a new root finder
-