public class RootSolver extends Object
NumFunction
in parameter. To find the root of the function,
the user can enter an interval of 2 points where the
function values at those endpoints
f (x0)f (x1) <= 0
or enter only one point and the algorithm will try to find
the second point to get an interval.Constructor and Description |
---|
RootSolver(NumFunction f)
Constructor for the root solver with default error tolerance
which are 0.01 absolute error tolerance
over the root point and 500 iterations.
|
RootSolver(NumFunction f,
double tol)
Constructor for the root solver with inputed tolerance and
stopping conditions.
|
Modifier and Type | Method and Description |
---|---|
double |
findRoot(double x0)
Finds a root around point
x0 . |
double |
findRoot(double x0,
double x1)
Finds a root between
x0 and x1 . |
double |
getCovergenceTol()
Returns the absolution convergence tolerance.
|
void |
setCovergenceTol(double t)
Sets the (absolute) convergence tolerance of the solution.
|
public RootSolver(NumFunction f)
f
- the function to find the root. It must be a single
variable function.public RootSolver(NumFunction f, double tol)
f
- the function to find the root. It must be a single
variable functiontol
- the absolute error tolerance for the difference
between the roots after each iteration (new value vs old value)public void setCovergenceTol(double t)
t
.t
- the absolute convergence tolerancepublic double getCovergenceTol()
public double findRoot(double x0)
x0
.
Note that this method may not work if the given starting point is too far
from a root value.x0
- the starting point of the root searchpublic double findRoot(double x0, double x1)
x0
and x1
. The values of the function
at point x0
and x1
must be of opposite signs, such that
f(x0) * f(x1) <= 0.x0
- first value of the interval to searchx1
- second value of the interval to searchDouble.NaN
if f(x0) * f(x1) > 0