public class NewtonFindRoot extends Object
Constructor and Description |
---|
NewtonFindRoot(RealValuedScalarFunction function,
double functionTolerance,
RealValuedScalarFunction derivativeFunction,
double derivativeTolerance,
double lowerBound,
double upperBound)
Initializes a new instance that can be used to find roots of a specified function.
|
Modifier and Type | Method and Description |
---|---|
boolean |
findRoot(int maxIterations)
Attempts the indicated number of iterations to locate the root of the function
to within the required convergence criteria.
|
RealValuedScalarFunction |
getDerivativeFunction()
Gets the derivative of
Function (get ). |
double |
getDerivativeTolerance()
Gets the tolerance used to determine whether the derivative is zero for the purposes of
aborting the calculation and setting the
ResultType (get ) to NewtonRootType.SOLVER_FAILED_DUE_TO_HORIZONTAL_SLOPE . |
double |
getDerivativeValue()
|
RealValuedScalarFunction |
getFunction()
Gets the evaluation function.
|
double |
getFunctionTolerance()
Gets the tolerance used to determine whether the function is zero and a root has been found.
|
double |
getFunctionValue()
|
int |
getIterations()
Gets the number of iterations taken.
|
double |
getLowerBound()
Gets the lower bound of the range of independent variables to search for the root within.
|
double |
getMaximumStepsize()
Gets the maximum size of the step to take during a single iteration.
|
NewtonRootType |
getResultType()
Gets the type of result the
Root (get ) represents. |
double |
getRoot()
Gets the value of the root.
|
double |
getUpperBound()
Gets the upper bound of the range of independent variables to search for the root within.
|
double |
getVariableTolerance()
Gets the tolerance used to determine whether a root guess is the same as another root guess, used in
early detection of non-convergence.
|
void |
setDerivativeTolerance(double value)
Sets the tolerance used to determine whether the derivative is zero for the purposes of
aborting the calculation and setting the
ResultType (get ) to NewtonRootType.SOLVER_FAILED_DUE_TO_HORIZONTAL_SLOPE . |
void |
setFunctionTolerance(double value)
Sets the tolerance used to determine whether the function is zero and a root has been found.
|
void |
setInitialGuessOfRootLocation(double guess)
Sets the initial guess of the root's location.
|
void |
setLowerBound(double value)
Sets the lower bound of the range of independent variables to search for the root within.
|
void |
setMaximumStepsize(double value)
Sets the maximum size of the step to take during a single iteration.
|
void |
setUpperBound(double value)
Sets the upper bound of the range of independent variables to search for the root within.
|
void |
setVariableTolerance(double value)
Sets the tolerance used to determine whether a root guess is the same as another root guess, used in
early detection of non-convergence.
|
public NewtonFindRoot(RealValuedScalarFunction function, double functionTolerance, RealValuedScalarFunction derivativeFunction, double derivativeTolerance, double lowerBound, double upperBound)
NewtonFindRoot.setInitialGuessOfRootLocation(double)
must be called before NewtonFindRoot.findRoot(int)
. MaximumStepsize
(get
/ set
) is set to
an initial value of Double.MAX_VALUE
, VariableTolerance
(get
/ set
) is set to an initial value of zero.function
- The Function
(get
) to find the root of.functionTolerance
- The FunctionTolerance
(get
/ set
) to use to determine whether the Function
(get
) is zero.derivativeFunction
- The DerivativeFunction
(get
) of the function.derivativeTolerance
- The DerivativeTolerance
(get
/ set
) to use to determine whether the DerivativeFunction
(get
) is zero.lowerBound
- The lower bound of the region to search for the root within.upperBound
- The upper bound of the region to search for the root within.public final boolean findRoot(int maxIterations)
maxIterations
- The maximum number of iterations to perform.
If a solution has not been found after this number of iterations the Root
(get
) property is set to the guess
of the last iteration and ResultType
(get
) is set to NewtonRootType.SOLUTION_DID_NOT_CONVERGE
.true
if the root was found; otherwise false
.public final double getFunctionTolerance()
public final void setFunctionTolerance(double value)
public final double getDerivativeTolerance()
ResultType
(get
) to NewtonRootType.SOLVER_FAILED_DUE_TO_HORIZONTAL_SLOPE
.public final void setDerivativeTolerance(double value)
ResultType
(get
) to NewtonRootType.SOLVER_FAILED_DUE_TO_HORIZONTAL_SLOPE
.public final double getVariableTolerance()
public final void setVariableTolerance(double value)
public final double getMaximumStepsize()
public final void setMaximumStepsize(double value)
public final int getIterations()
public final double getRoot()
ResultType
(get
) property
for whether the calculated root is the result of a finished calculation, or some other failure condition
such as the failure to converge in the allotted number of maximum iterations.public final void setInitialGuessOfRootLocation(double guess)
Root
(get
) to the provided guess, ResultType
(get
)
to NewtonRootType.INITIAL_GUESS
and Iterations
(get
) is set to 0.
If Function
(get
) and/or DerivativeFunction
(get
) are non-null the method also assigns
assigns FunctionValue
(get
) and DerivativeValue
(get
) respectively.guess
- The guess of the roots location.public final double getFunctionValue()
public final double getDerivativeValue()
@Nonnull public final NewtonRootType getResultType()
Root
(get
) represents.public final double getLowerBound()
public final void setLowerBound(double value)
public final double getUpperBound()
public final void setUpperBound(double value)
public final RealValuedScalarFunction getFunction()
public final RealValuedScalarFunction getDerivativeFunction()
Function
(get
).