com.isti.util.math
Class CubicSpline

java.lang.Object
  extended by com.isti.util.ErrorMessageMgr
      extended by com.isti.util.math.CubicSpline
All Implemented Interfaces:
ErrorMsgMgrIntf

public class CubicSpline
extends ErrorMessageMgr


Field Summary
static double TRIG_ARG_MAX
          Maximum value for magnitude of x, beyond which we approximate x/sinh(x) and x/tanh(x) by |x|exp(-|x|).
static double TRIG_ARG_MIN
          Minimum value for magnitude of x, for such functions as x-sinh(x), x-tanh(x), x-sin(x), and x-tan(x) to have acceptable accuracy.
 
Constructor Summary
CubicSpline()
           
 
Method Summary
 double[] calcSpline(double[] t, double[] y, double tension, double k, double[] xValsArr)
          Performs cubic spline interpolation.
 double[] fit(double[] t, double[] y, double k, double tension, boolean periodic)
          Computes the array of second derivatives at the knots, i.e., internal data points.
static double interpolate(double[] t, double[] y, double[] z, double x, double tension, boolean periodic)
          Computes an approximate ordinate value for a given abscissa value, given an array of data points (stored in t[] and y[], containing abscissa and ordinate values respectively), and z[], the array of 2nd derivatives at the knots (i.e.
 boolean isMonotonic(double[] t)
          Checks whether an array of data points has monotonic values.
static double quotient_sin_func(double x, double y)
          These two functions compute (6/y^2)(sinh(xy)/sinh(y)-x) and (6/y^2)(sin(xy)/sin(y)-x), via the first three terms of the appropriate power series in y.
static double quotient_sinh_func(double x, double y)
          These two functions compute (6/y^2)(sinh(xy)/sinh(y)-x) and (6/y^2)(sin(xy)/sin(y)-x), via the first three terms of the appropriate power series in y.
static double sin_func(double x)
          These four functions compute (6/x^2)(1-x/sinh(x)), (3/x^2)(x/tanh(x)-1), (6/x^2)(1-x/sin(x)), and (3/x^2)(x/tan(x)-1) via the first three terms of the appropriate power series.
static double sinh_func(double x)
          These four functions compute (6/x^2)(1-x/sinh(x)), (3/x^2)(x/tanh(x)-1), (6/x^2)(1-x/sin(x)), and (3/x^2)(x/tan(x)-1) via the first three terms of the appropriate power series.
static double sinh(double value)
          Returns the hyperbolic sine of a double value.
static double tan_func(double x)
          These four functions compute (6/x^2)(1-x/sinh(x)), (3/x^2)(x/tanh(x)-1), (6/x^2)(1-x/sin(x)), and (3/x^2)(x/tan(x)-1) via the first three terms of the appropriate power series.
static double tanh_func(double x)
          These four functions compute (6/x^2)(1-x/sinh(x)), (3/x^2)(x/tanh(x)-1), (6/x^2)(1-x/sin(x)), and (3/x^2)(x/tan(x)-1) via the first three terms of the appropriate power series.
static double tanh(double value)
          Returns the hyperbolic tangent of a double value.
 
Methods inherited from class com.isti.util.ErrorMessageMgr
clearErrorMessageString, clearFetchedErrorMessage, enterErrorMessageString, getErrorMessageFlag, getErrorMessageString, getUnfetchedMessageFlag, setErrorMessageString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRIG_ARG_MIN

public static double TRIG_ARG_MIN
Minimum value for magnitude of x, for such functions as x-sinh(x), x-tanh(x), x-sin(x), and x-tan(x) to have acceptable accuracy. If the magnitude of x is smaller than this value, these functions of x will be computed via power series to accuracy O(x**6).


TRIG_ARG_MAX

public static double TRIG_ARG_MAX
Maximum value for magnitude of x, beyond which we approximate x/sinh(x) and x/tanh(x) by |x|exp(-|x|).

Constructor Detail

CubicSpline

public CubicSpline()
Method Detail

calcSpline

public double[] calcSpline(double[] t,
                           double[] y,
                           double tension,
                           double k,
                           double[] xValsArr)
Performs cubic spline interpolation. Two "source" arrays (abscissa 'X' and ordinate 'Y' values) and an array of "new" abscissa values are given; an array of "destination" ordinate values is generated and returned. If any "new" abscissa values are outside of the range of "source" abscissa values then the method will return an error message.

Parameters:
t - abscissa "source" array of 'double' values.
y - ordinate "source" array of 'double' values.
tension - tension value for interpolation, use 0.0 as default value: If tension=0 then a spline with tension reduces to a conventional piecewise cubic spline. In the limits tension->+infinity and tension->-infinity, a spline with tension reduces to a piecewise linear (`broken line') interpolation. To oversimplify a bit, 1.0/tension is the maximum abscissa range over which the spline likes to curve, at least when tension>0. So increasing the tension far above zero tends to make the spline contain short curved sections, separated by sections that are almost straight. The curved sections will be centered on the user-specified data points. The behavior of the spline when tension<0 is altogether different: it will tend to oscillate, though as tension->-infinity the oscillations are damped out.
k - boundary condition, use 1.0 as default value: Appears in the two boundary conditions y''[0]=ky''[1] and y''[n]=ky''[n-1].
xValsArr - array of "new" abscissa values to use with interpolation ('double' values).
Returns:
A new 'double' array interpolated values; or null if an error occurs (in which case the error message may be fetched via the 'getErrorMessageString()' method).

fit

public double[] fit(double[] t,
                    double[] y,
                    double k,
                    double tension,
                    boolean periodic)
Computes the array of second derivatives at the knots, i.e., internal data points. The abscissa array t[] and the ordinate array y[] are specified. On entry, have n+1 >= 2 points in the t and y arrays, numbered 0..n. The knots are numbered 1..n-1 as in Kincaid and Cheney. In the periodic case, the final knot, i.e., (t[n-1],y[n-1]), has the property that y[n-1]=y[0]; moreover, y[n]=y[1]. The number of points supplied by the user was n+1 in the non-periodic case, and n in the periodic case. When this function is called, n>=1 in the non-periodic case, and n>=2 in the periodic case. Algorithm: the n-1 by n-1 tridiagonal matrix equation for the vector of 2nd derivatives at the knots is reduced to upper diagonal form. At that point the diagonal entries (pivots) of the upper diagonal matrix are in the vector u[], and the vector on the right-hand side is v[]. That is, the equation is of the form Ay'' = v, where a_(ii) = u[i], and a_(i,i+1) = alpha[i]. Here i=1..n-1 indexes the set of knots. The matrix equation is solved by back-substitution for y''[], i.e., for z[].

Parameters:
t - abscissa array of 'double' values.
y - ordinate array of 'double' values.
k - boundary condition, use 1.0 as default value; appears in the two boundary conditions y''[0]=ky''[1] and y''[n]=ky''[n-1].
tension - tension value for interpolation.
periodic - true for periodic; false for non-periodic.
Returns:
A new 'double' array of second derivatives; or null if an error occurs (in which case the error message may be fetched via the 'getErrorMessageString()' method).

interpolate

public static double interpolate(double[] t,
                                 double[] y,
                                 double[] z,
                                 double x,
                                 double tension,
                                 boolean periodic)
Computes an approximate ordinate value for a given abscissa value, given an array of data points (stored in t[] and y[], containing abscissa and ordinate values respectively), and z[], the array of 2nd derivatives at the knots (i.e. internal data points). On entry, have n+1 >= 2 points in the t, y, z arrays, numbered 0..n. The number of knots (i.e. internal data points) is n-1; they are numbered 1..n-1 as in Kincaid and Cheney. In the periodic case, the final knot, i.e., (t[n-1],y[n-1]), has the property that y[n-1]=y[0]; also, y[n]=y[1]. The number of data points supplied by the user was n+1 in the non-periodic case, and n in the periodic case. When this function is called, n>=1 in the non-periodic case, and n>=2 in the periodic case.


isMonotonic

public final boolean isMonotonic(double[] t)
Checks whether an array of data points has monotonic values.

Parameters:
t - array of double values to be checked.
Returns:
true if the given array is monotonic; false if not.

sinh

public static double sinh(double value)
Returns the hyperbolic sine of a double value. The hyperbolic sine of x is defined to be (ex - e-x)/2 where e is Euler's number.

Parameters:
value - The number whose hyperbolic sine is to be returned.
Returns:
The hyperbolic sine of x.

tanh

public static double tanh(double value)
Returns the hyperbolic tangent of a double value. The hyperbolic tangent of x is defined to be (ex - e-x)/ (ex + e-x), in other words, sinh(x)/cosh(x). Note that the absolute value of the exact tanh is always less than 1.

Parameters:
value - The number whose hyperbolic tangent is to be returned.
Returns:
The hyperbolic tangent of x.

sinh_func

public static double sinh_func(double x)
These four functions compute (6/x^2)(1-x/sinh(x)), (3/x^2)(x/tanh(x)-1), (6/x^2)(1-x/sin(x)), and (3/x^2)(x/tan(x)-1) via the first three terms of the appropriate power series. They are used when |x|

tanh_func

public static double tanh_func(double x)
These four functions compute (6/x^2)(1-x/sinh(x)), (3/x^2)(x/tanh(x)-1), (6/x^2)(1-x/sin(x)), and (3/x^2)(x/tan(x)-1) via the first three terms of the appropriate power series. They are used when |x|

sin_func

public static double sin_func(double x)
These four functions compute (6/x^2)(1-x/sinh(x)), (3/x^2)(x/tanh(x)-1), (6/x^2)(1-x/sin(x)), and (3/x^2)(x/tan(x)-1) via the first three terms of the appropriate power series. They are used when |x|

tan_func

public static double tan_func(double x)
These four functions compute (6/x^2)(1-x/sinh(x)), (3/x^2)(x/tanh(x)-1), (6/x^2)(1-x/sin(x)), and (3/x^2)(x/tan(x)-1) via the first three terms of the appropriate power series. They are used when |x|

quotient_sinh_func

public static double quotient_sinh_func(double x,
                                        double y)
These two functions compute (6/y^2)(sinh(xy)/sinh(y)-x) and (6/y^2)(sin(xy)/sin(y)-x), via the first three terms of the appropriate power series in y. They are used when |y|

quotient_sin_func

public static double quotient_sin_func(double x,
                                       double y)
These two functions compute (6/y^2)(sinh(xy)/sinh(y)-x) and (6/y^2)(sin(xy)/sin(y)-x), via the first three terms of the appropriate power series in y. They are used when |y|