public class NewtonRaphsonSingleRootFinder extends RealSingleRootFinder
For a function $f(x)$, the Taylor series expansion is given by: $$ \begin{align*} f(x + \delta) \approx f(x) + f'(x)\delta + \frac{f''(x)}{2}\delta^2 + \cdots \end{align*} $$ As delta approaches zero (and if the function is well-behaved), this gives $$ \begin{align*} \delta = -\frac{f(x)}{f'(x)} \end{align*} $$ when $f(x + \delta) = 0$.
There are several well-known problems with Newton's method, in particular when the range of values given includes a local maximum or minimum. In this situation, the next iterative step can shoot off to $\pm\infty$. This implementation currently does not attempt to correct for this: if the value of $x$ goes beyond the initial range of values $x_{low}$ and $x_{high}$, an exception is thrown.
If the function that is provided does not override the DoubleFunction1D.derivative()
method, then the derivative is approximated using finite difference. This is undesirable for several reasons:
(i) the extra function evaluations will lead to slower convergence; and
(ii) the choice of shift size is very important (too small and the result will be dominated by rounding errors, too large
and convergence will be even slower). Use of another root-finder is recommended in this case.
| Constructor and Description |
|---|
NewtonRaphsonSingleRootFinder()
Default constructor.
|
NewtonRaphsonSingleRootFinder(double accuracy)
Takes the accuracy of the root as a parameter - this is the maximum difference
between the true root and the returned value that is allowed.
|
| Modifier and Type | Method and Description |
|---|---|
Double |
getRoot(DoubleFunction1D function,
Double x)
Uses the
DoubleFunction1D.derivative() method. |
Double |
getRoot(DoubleFunction1D function,
Double x1,
Double x2)
Uses the
DoubleFunction1D.derivative() method. |
Double |
getRoot(DoubleFunction1D function,
DoubleFunction1D derivative,
Double x)
Uses the function and its derivative.
|
Double |
getRoot(DoubleFunction1D function,
DoubleFunction1D derivative,
Double x1,
Double x2)
Uses the function and its derivative.
|
Double |
getRoot(Function<Double,Double> function,
Double x) |
Double |
getRoot(Function<Double,Double> function,
Double x1,
Double x2) |
Double |
getRoot(Function<Double,Double> function,
Function<Double,Double> derivative,
Double x)
Uses the function and its derivative.
|
Double |
getRoot(Function<Double,Double> function,
Function<Double,Double> derivative,
Double x1,
Double x2)
Uses the function and its derivative.
|
checkInputs, checkInputs, getRootpublic NewtonRaphsonSingleRootFinder()
public NewtonRaphsonSingleRootFinder(double accuracy)
accuracy - The accuracypublic Double getRoot(Function<Double,Double> function, Double x1, Double x2)
getRoot in class RealSingleRootFinderMathException - If the root is not found in 1000 attempts; if the Newton
step takes the estimate for the root outside the original bounds.public Double getRoot(DoubleFunction1D function, Double x1, Double x2)
DoubleFunction1D.derivative() method. x1 and
x2 do not have to be increasing.function - The function, not nullx1 - The first bound of the root, not nullx2 - The second bound of the root, not nullMathException - If the root is not found in 1000 attempts; if the Newton
step takes the estimate for the root outside the original bounds.public Double getRoot(DoubleFunction1D function, Double x)
DoubleFunction1D.derivative() method. This method uses an initial
guess for the root, rather than bounds.function - The function, not nullx - The initial guess for the root, not nullMathException - If the root is not found in 1000 attempts.public Double getRoot(Function<Double,Double> function, Function<Double,Double> derivative, Double x1, Double x2)
function - The function, not nullderivative - The derivative, not nullx1 - The first bound of the root, not nullx2 - The second bound of the root, not nullMathException - If the root is not found in 1000 attempts; if the Newton
step takes the estimate for the root outside the original bounds.public Double getRoot(Function<Double,Double> function, Function<Double,Double> derivative, Double x)
function - The function, not nullderivative - The derivative, not nullx - The initial guess for the root, not nullMathException - If the root is not found in 1000 attempts.public Double getRoot(DoubleFunction1D function, DoubleFunction1D derivative, Double x1, Double x2)
function - The function, not nullderivative - The derivative, not nullx1 - The first bound of the root, not nullx2 - The second bound of the root, not nullMathException - If the root is not found in 1000 attempts; if the Newton
step takes the estimate for the root outside the original bounds.public Double getRoot(DoubleFunction1D function, DoubleFunction1D derivative, Double x)
function - The function, not nullderivative - The derivative, not nullx - The initial guess for the root, not nullMathException - If the root is not found in 1000 attempts.Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.