|
|||||||||
PREV CLASS NEXT CLASS | All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjhplot.math.num.IterativeMethod
jhplot.math.num.root.SecantRootFinder
public class SecantRootFinder
The secant 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); }} };
Then, a secant root finder is created with the above function:
SecantRootFinder finder = new SecantRootFinder(sine);
Lastly, locating roots is accomplished using the findRoot(double, double)
method:
// find the root around 3 and 4. double pi = finder.findRoot(3.0, 4.0); // find the root around 3.5 and 4. pi = finder.findRoot(3.5, 4.0); // find the root around -1 and 1. double zero = finder.findRoot(-1.0, 1.0);
References:
Nested Class Summary |
---|
Nested classes/interfaces inherited from class jhplot.math.num.IterativeMethod |
---|
IterativeMethod.IterativeState |
Constructor Summary | |
---|---|
SecantRootFinder(Function f)
Create a root finder for the given function. |
|
SecantRootFinder(Function f,
int iterations,
double error)
Create a root finder for the given function. |
Method Summary | |
---|---|
double |
findRoot(double x0,
double x1)
Find a root of the target function that lies around the two initial approximations, x0 and x1. |
Function |
getFunction()
Access 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 |
---|
public SecantRootFinder(Function f)
f
- the target function.public SecantRootFinder(Function f, int iterations, double error)
f
- the target function.iterations
- maximum number of iterations.error
- maximum relative error.Method Detail |
---|
public double findRoot(double x0, double x1) throws NumericException
x0
- an initial approximation to the root.x1
- another initial approximation to the root.
NumericException
- if a root could not be found.public Function getFunction()
public void setFunction(Function f)
f
- the new target function.
|
|||||||||
PREV CLASS NEXT CLASS | All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |