Package dev.nm.analysis.root.univariate
Class NewtonRoot
- java.lang.Object
-
- dev.nm.analysis.root.univariate.NewtonRoot
-
- All Implemented Interfaces:
Uniroot
public class NewtonRoot extends Object implements Uniroot
The Newton-Raphson method is as follows: one starts with an initial guess which is reasonably close to the true root, then the function is approximated by its tangent line (which can be computed using the tools of calculus), and one computes the x-intercept of this tangent line (which is easily done with elementary algebra). This x-intercept will typically be a better approximation to the function's root than the original guess, and the method can be iterated. It has the following properties.- The function to be solved is assumed to be continuous and smooth (1st derivative exists).
- The solution converges quadratically, when the multiplicity of the root is 1; otherwise, it is linear.
- The solution may fail to converge when the derivative is or is close to 0.
- The solution may fail to converge if the initial guess is far away from the true value.
- See Also:
- Wikipedia: Newton's method
-
-
Constructor Summary
Constructors Constructor Description NewtonRoot(double tol, int maxIterations)
Constructs an instance of Newton's root finding algorithm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
solve(UnivariateRealFunction f, double guess)
double
solve(UnivariateRealFunction f, double lower, double upper, double... guess)
Search for a root, x, in the interval [lower, upper] such that f(x) = 0.double
solve(UnivariateRealFunction f, UnivariateRealFunction df_, double guess)
Searches for a root, x, in the interval [lower, upper] such that f(x) = 0.
-
-
-
Method Detail
-
solve
public double solve(UnivariateRealFunction f, double lower, double upper, double... guess) throws NoRootFoundException
Description copied from interface:Uniroot
Search for a root, x, in the interval [lower, upper] such that f(x) = 0.- Specified by:
solve
in interfaceUniroot
- Parameters:
f
- a univariate functionlower
- the lower bound of the bracketing intervalupper
- the upper bound of the bracketing intervalguess
- an initial guess of the root within [lower, upper]. Note thatguess
is adouble[]
. This signature allows multiple initial guesses for certain types of uniroot algorithms, e.g., Brent's algorithm.- Returns:
- an approximate root
- Throws:
NoRootFoundException
- when the search fails to find a root
-
solve
public double solve(UnivariateRealFunction f, double guess) throws NoRootFoundException
- Throws:
NoRootFoundException
-
solve
public double solve(UnivariateRealFunction f, UnivariateRealFunction df_, double guess) throws NoRootFoundException
Searches for a root, x, in the interval [lower, upper] such that f(x) = 0.- Parameters:
f
- a univariate functiondf_
- the first order derivativeguess
- an initial guess of the root within [lower, upper]- Returns:
- an approximate root
- Throws:
NoRootFoundException
- when the search fails to find a root
-
-