public class BrentRootFinder extends IterativeMethod
Brent's method (1) for finding roots of functions.
For example, to find roots for sine, first a
Function
is defined:
Function sine = new Function() { public double evaluate(double x) { return Math.sin(x); }} };
Then, a Brent's method root finder is created with the above function:
BrentRootFinder finder = new BrentRootFinder(sine);
Lastly, locating roots is accomplished using the findRoot(double, double)
method:
// find the root between 3 and 4. double pi = finder.findRoot(3.0, 4.0); // find the root between -1 and 1. double zero = finder.findRoot(-1.0, 1.0);
References:
IterativeMethod.IterativeState
Constructor and Description |
---|
BrentRootFinder(Function f)
Create a root finder for the given function.
|
BrentRootFinder(Function f,
int iterations,
double error)
Create a root finder for the given function.
|
Modifier and Type | Method and Description |
---|---|
double |
findRoot(double min,
double max)
Find a root of the target function that lies between the two initial
approximations, x0 and x1.
|
Function |
getFunction()
Access the target function.
|
void |
setFunction(Function f)
Modify the target function.
|
getMaximumIterations, getMaximumRelativeError, iterate, setMaximumIterations, setMaximumRelativeError
public BrentRootFinder(Function f)
f
- the target function.public BrentRootFinder(Function f, int iterations, double error)
f
- the target function.iterations
- maximum number of iterations.error
- maximum relative error.public double findRoot(double min, double max) throws NumericException
min
- the lower bound of the search interval.max
- the upper bound of the search interval.NumericException
- if a root could not be found.public Function getFunction()
public void setFunction(Function f)
f
- the new target function.Jas4pp 1.5 © Java Analysis Studio for Particle Physics