public class Roots extends java.lang.Object
Modified by: Joseph A. Huwaldt
Constructor and Description |
---|
Roots() |
Modifier and Type | Method and Description |
---|---|
static double |
aitken(Evaluatable1D eval,
double x,
double tol)
Find a root of a 1D equation using the Aitken method.
|
static int |
bracket(Evaluatable1D func,
double x1,
double x2,
int n,
double[] xb1,
double[] xb2)
Given a function,
func , defined on the interval x1 to
x2 , this routine subdivides the interval into n equally
spaced segments, and searches for zero crossings of the function. |
static double |
findRoot1D(Evaluatable1D eval,
BracketRoot1D bracket,
double tol)
Find the root of a general 1D function
f(x) = 0 known to lie between
x1 and x2 . |
static double |
findRoot1D(Evaluatable1D eval,
double x1,
double x2,
double tol)
Find the root of a general 1D function
f(x) = 0 known to lie between
x1 and x2 . |
static boolean |
findRootsND(VectorFunction vecfunc,
double[] x,
int n)
Find the roots of a set of
N non-linear equations in N
variables. |
static void |
main(java.lang.String[] args)
Used to test out the methods in this class.
|
public Roots()
public static int bracket(Evaluatable1D func, double x1, double x2, int n, double[] xb1, double[] xb2) throws RootException
func
, defined on the interval x1
to
x2
, this routine subdivides the interval into n
equally
spaced segments, and searches for zero crossings of the function. Brackets around
any zero crossings found are returned.func
- The function that is being search for zero crossings.x1
- The start of the interval to be searched.x2
- The end of the interval to be searched.n
- The number segments to divide the interval into.xb1
- Lower value of each bracketing pair found (number of pairs is returned
by function). The size of the array determines the maximum number of
bracketing pairs that will be found.xb2
- Upper value of each bracketing pair found (number of pairs is returned
by function). The size of this array must match the size of
xb1
.RootException
- if the supplied function can not accept
the interval provided.public static double findRoot1D(Evaluatable1D eval, BracketRoot1D bracket, double tol) throws RootException
f(x) = 0
known to lie between
x1
and x2
. The root will be refined until it's accuracy
is tol
.
Have your Evaluatable1D derivative()
function return
Double.NaN
when you want this routine to use Brent's method.
Newton-Raphson will be used if a derivative function is provided that returns
something other than Double.NaN
. The function()
method
will always be called before the derivative()
method. The value
returned from the 1st call to the function()
method is ignored.
eval
- An evaluatable 1D function that returns the function value at x and
optionally returns the function derivative value (d(fx)/dx) at x. It
is guaranteed that "function()" will always be called before
"derivative()".bracket
- The upper and lower bracket surrounding the root (assumed that root
lies inside the bracket).tol
- The root will be refined until it's accuracy is better than this.RootException
- if unable to find a root of the function.public static double findRoot1D(Evaluatable1D eval, double x1, double x2, double tol) throws RootException
f(x) = 0
known to lie between
x1
and x2
. The root will be refined until it's accuracy
is tol
.
Have your Evaluatable1D derivative()
function return
Double.NaN
when you want this routine to use Brent's method.
Newton-Raphson will be used if a derivative function is provided that returns
something other than Double.NaN
. The function()
method
will always be called before the derivative()
method. The value
returned from the 1st call to the function()
method is ignored.
eval
- An evaluatable 1D function that returns the function value at x and
optionally returns the function derivative value (d(fx)/dx) at x. It is
guaranteed that "function()" will always be called before
"derivative()".x1
- The lower bracket surrounding the root (assumed that root lies between
x1 and x2).x2
- The upper bracket surrounding the root (assumed that root lies between
x1 and x2).tol
- The root will be refined until it's accuracy is better than this.RootException
- Unable to find a root of the function.public static double aitken(Evaluatable1D eval, double x, double tol) throws RootException
eval
- An evaluatable 1D function that returns the function value at x and
optionally returns the function derivative value (d(fx)/dx) at x. This
method never calls "derivative()".x
- A starting guess at the root value.tol
- The root will be refined until it's accuracy is better than this.RootException
- if unable to find a root of the function.public static boolean findRootsND(VectorFunction vecfunc, double[] x, int n) throws RootException
N
non-linear equations in N
variables.
Uses a globally convergent Newton's method with either a Jacobian supplied by the VectorFunction or one computed by differencing.
Reference: Numerical Recipes in C, 2nd Edition, pg 386.
vecfunc
- A VectorFunction that computes the values for each equation using
the input values in x[] and optionally the Jacobian.x
- A pre-existing array that contains the initial guesses at the x
values. On completion, it will contain the roots of the equations.n
- The number of equations to be solved (and the number of elements in
x.false
if the routine completed normally or true
if the routine has converged to a local minimum of the "fmin" function. In
this case, try restarting from a different initial guess.RootException
- Unable to find the roots of the functions.public static void main(java.lang.String[] args)
args
- Command line arguments (not used).