Documentation API of the 'jhplot.math.num.root.NewtonRootFinder' Java class
NewtonRootFinder
jhplot.math.num.root

Class NewtonRootFinder

• `public class NewtonRootFinderextends IterativeMethod`

Newton'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);    }} }; `
along with its derivative:
` Function cos = new Function() {    public double evaluate(double x) {        return Math.cos(x);    }} }; `

Then, a Newton's method root finder is created with the above function:

` NewtonRootFinder finder = new NewtonRootFinder(sine, cos); `

Lastly, locating roots is accomplished using the `findRoot(double)` method:

` // find the root close to 3. double pi = finder.findRoot(3.0);  // find the root between close to 1. double zero = finder.findRoot(1.0); `

References:

1. Eric W. Weisstein. "Newton's Method." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/NewtonsMethod.html

• Constructor Summary

Constructors
Constructor and Description
`NewtonRootFinder(Function f, Function d)`
Create a root finder for the given function.
`NewtonRootFinder(Function f, Function d, int iterations, double error)`
Create a root finder for the given function.
• Method Summary

All Methods
Modifier and TypeMethod and Description
`double``findRoot(double x)`
Find a root of the target function that lies close to x.
`Function``getDerivative()`
Access the derivative of the target function.
`Function``getFunction()`
Access the target function.
`void``setDerivative(Function f)`
Modify the derivative of the target function.
`void``setFunction(Function f)`
Modify the target function.
• Methods inherited from class jhplot.math.num.IterativeMethod

`getMaximumIterations, getMaximumRelativeError, iterate, setMaximumIterations, setMaximumRelativeError`
• Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• Constructor Detail

• NewtonRootFinder

`public NewtonRootFinder(Function f,                        Function d)`
Create a root finder for the given function.
Parameters:
`f` - the target function.
`d` - the first derivative of f.
• NewtonRootFinder

`public NewtonRootFinder(Function f,                        Function d,                        int iterations,                        double error)`
Create a root finder for the given function.
Parameters:
`f` - the target function.
`d` - the first derivative of f.
`iterations` - maximum number of iterations.
`error` - maximum relative error.
• Method Detail

• findRoot

`public double findRoot(double x)                throws NumericException`
Find a root of the target function that lies close to x.
Parameters:
`x` - the initial root approximation.
Returns:
a root that lies close to x.
Throws:
`NumericException` - if a root could not be found.
• getDerivative

`public Function getDerivative()`
Access the derivative of the target function.
Returns:
the target function derivative.
• getFunction

`public Function getFunction()`
Access the target function.
Returns:
the target function.
• setDerivative

`public void setDerivative(Function f)`
Modify the derivative of the target function.
Parameters:
`f` - the new target function derivative.
• setFunction

`public void setFunction(Function f)`
Modify the target function.
Parameters:
`f` - the new target function.

DMelt 1.2 © DataMelt by jWork.ORG

NewtonRootFinder
jhplot.math.num.root

Class NewtonRootFinder

• `public class NewtonRootFinderextends IterativeMethod`

Newton'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);    }} }; `
along with its derivative:
` Function cos = new Function() {    public double evaluate(double x) {        return Math.cos(x);    }} }; `

Then, a Newton's method root finder is created with the above function:

` NewtonRootFinder finder = new NewtonRootFinder(sine, cos); `

Lastly, locating roots is accomplished using the `findRoot(double)` method:

` // find the root close to 3. double pi = finder.findRoot(3.0);  // find the root between close to 1. double zero = finder.findRoot(1.0); `

References:

1. Eric W. Weisstein. "Newton's Method." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/NewtonsMethod.html

Warning: You cannot see the full API documentation of this class since the access to the DatMelt documentation for third-party Java classes is denied. Guests can only view jhplot Java API. To view the complete description of this class and its methods, please request the full DataMelt membership.

If you are already a full member, please login to the DataMelt member area before visiting this documentation.