public class PnRootFinder
extends java.lang.Object
Constructor and Description |
---|
PnRootFinder() |
Modifier and Type | Method and Description |
---|---|
static PdVector |
findRoots(PuFunction fx,
double x1,
double x2,
int maxRoots)
Given a function fx on the interval I=[x1,x2] and a subdivision of I into maxRoots
equally spaced subintervals, then find those subintervals with zero crossing
and compute a root for each subinterval.
|
static double[] |
findValue(PuFunction fx,
double[] a,
double[] b,
double value)
Finds the position of a value on a straight line segment between
two vertices using a bisection algorithm.
|
static double[] |
findZero(PuFunction fx,
double[] a,
double[] b)
Finds the zero position on a straight line segment between
two vertices using a bisection algorithm.
|
static double[] |
zbrac(PuFunction fx,
double x1,
double x2)
Given a function fx and initial interval I=[x1,x2], then the method expands
the range until a root is bracketed by the returned array.
|
static int |
zbrak(PuFunction fx,
double x1,
double x2,
int len,
double[] xb1,
double[] xb2,
int nb)
Given a function fx on the interval I=[x1,x2] and a subdivision of I into len
equally spaced subintervals, then find those subintervals with zero crossing
and return them as array brackets.
|
static double |
zbrent(PuFunction fx,
double x1,
double x2,
double tol)
Given a function fx find a root known to lie in the interval I=[x1,x2].
|
public static double[] findZero(PuFunction fx, double[] a, double[] b)
This method just calls #findValue
with value of zero.
a
- a double[] with one vertexb
- a double[] with another vertexpublic static double[] findValue(PuFunction fx, double[] a, double[] b, double value)
First the function is evaluated at the two end points. If either of them is already equal to the value, then a copy of this vertex is returned. If both values are bigger or smaller, then a warning message is issued and the first vertex is returned.
Otherwise the bisection starts by computing the midpoint of the interval, choosing the section with different signs for the difference, bisecting this subinterval again and so on until one of the function values becomes equal. This vertex is finally returned.
HACK: Method should use more efficient root finding algorithm.
a
- coordinates of the first vertexb
- coordinates of the second vertexvalue
- function value to search for its argument vertexpublic static PdVector findRoots(PuFunction fx, double x1, double x2, int maxRoots)
Method uses zbrak to find subintervals with zero crossings, and use zbrent to compute the root on each subinterval which is known to contain a root.
fx
- Function to evaluate for zero crossings.x1
- Original interval [x1,x2].x2
- Original interval [x1,x2].maxRoots
- Number of subintervals to in which to divide interval [x1,x2].zbrak(jv.function.PuFunction, double, double, int, double[], double[], int)
,
zbrent(jv.function.PuFunction, double, double, double)
,
PjRootFinder
public static double[] zbrac(PuFunction fx, double x1, double x2)
fx
- Function to evaluate for zero crossings.x1
- Original interval [x1,x2].x2
- Original interval [x1,x2].null
if maximal num of tries exceeded.zbrak(jv.function.PuFunction, double, double, int, double[], double[], int)
public static int zbrak(PuFunction fx, double x1, double x2, int len, double[] xb1, double[] xb2, int nb)
fx
- Function to evaluate for zero crossings.x1
- Original interval [x1,x2].x2
- Original interval [x1,x2].len
- Number of subintervals to in which to divide interval [x1,x2].xb1
- Array of size len to store the brackets of zero crossings [xb1,xb2].xb2
- Array of size len to store the brackets of zero crossings [xb1,xb2].nb
- Requested maximal number of zero crossings.zbrac(jv.function.PuFunction, double, double)
public static double zbrent(PuFunction fx, double x1, double x2, double tol)
fx
- Function to evaluate.x1
- Interval [x1,x2] containing a root of fx.x2
- Interval [x1,x2] containing a root of fx.tol
- Required precision.zbrac(jv.function.PuFunction, double, double)
"