public class NewtonRootFinder extends 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:
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.
|
Modifier and Type | Method 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.
|
getMaximumIterations, getMaximumRelativeError, iterate, setMaximumIterations, setMaximumRelativeError
public NewtonRootFinder(Function f, Function d)
f
- the target function.d
- the first derivative of f.public double findRoot(double x) throws NumericException
x
- the initial root approximation.NumericException
- if a root could not be found.public Function getDerivative()
public Function getFunction()
public void setDerivative(Function f)
f
- the new target function derivative.public void setFunction(Function f)
f
- the new target function.Jas4pp 1.5 © Java Analysis Studio for Particle Physics