Michael Thomas Flanagan's Java Scientific Library

PolyCubicSpline Class:      Multi-dimensional Cubic Spline Interpolation

     

Last update:11 September 2012                                                                                                                              Main Page of Michael Thomas Flanagan's Java Scientific Library

This class contains the constructor and method for performing a multi-dimensional cubic spline interpolation, i.e. an interpolation within a n-dimensional array of data points, y = f(x1,x2,x3 . . . xn), using a natural cubic splines and where n may take any integer value. The interpolation procedure is recursive.

If the number of dimension, n, of the data array, y = f(x1,x2,x3 . . . xn), is less than five you may find CubicSpline [n = 1], BiCubicSpline [n = 2], TriCubicSpline [n = 3] or QuadriCubicSpline [n = 4] more convenient and these classes are slightly more efficient.

See PolyCubicSplineFast.html for a version with all the data checking statements and methods removed allowing faster execution times.

import directive: import flanagan.interpolation.PolyCubicSpline;

SUMMARY OF CONSTRUCTOR AND METHODS

Constructor public PolyCubicSpline(Object xValues, Object yValues)
Interpolate public double interpolate(double[] xCoordinates)
Rounding Error Options public static void noRoundingErrorCheck()
public static void potentialRoundingError(double potentialRoundingError)



CONSTRUCTOR

CONSTRUCTOR
public PolyCubicSpline(Object xValues, Object yValues)
Usage:                      PolyCubicSpline aa = new PolyCubicSpline(xValues, yValues);
Creates an instance of the PolyCubicSpline object with its internal data arrays initialised the values in xValues and yValues containing the tabulated data for the arrays x1,x2,x3 . . . xn and for y = f(x1,x2,x3 . . . xn).
The argument xValues is a two dimensional array of doubles in which xValues[0] is the array of x1 values, i.e. {xValue[0][0] to xValue[0][p-1]}, xValues[1] is the array of x2 values i.e. {xValue[1][0] to xValue[1][q-1]}, . . . and xValues[n-1] is the array of xn i.e. {xValue[n-1][0] to xValue[n-1][r-1]} where there are p values x1, q values of x2, ..... r values of xn.
The argument yValues is an n-dimensional array of doubles containing the tabulated values of y = f(x1,x2,x3 . . . xn). The yValues elements are ordered as in the order of the following nested for loops if you were reading in or calculating the tabulated data:
for(int i=0; i<x1.length; i++){
       for(int j=0; j<x2.length; j++){
              for(int k=0; k<x3.length; k++){
                     for(int l=0; l<x4.length; l++){
                            for(int m=0; m<x5.length; m++){
                                   yValues[i][j][k][l][m] = 'read statement' or 'calculation of f(x1, x2, x3, x4, x5)';
                            }
                     }
              }
       }
}



METHODS

INTERPOLATION
public double interpolate(double[] xCoordinates)
Usage:                      y1 = aa.interpolate(xx);
Returns the interpolated value of y, y1, for n given values of x1, x2, x3 . . . xn, entered as the two dimensional array, xx, using the y = f(x1,x2,x3 . . . xn) data entered via the constructor. This method may be called as often as required. The interpolation procedure is recursive. g the y = f(x1,x2) data entered via the constructor. This method may be called as often as required. The inner second derivatives needed for the interpolation are calculated and stored on instantiation so that they need not be recalculated on each call to this method.



ROUNDING ERROR OPTIONS
public static void noRoundingErrorCheck()
Usage:                      PolyCubicSpline.noRoundingErrorCheck();
Seveveral applications that call PolyCubicSpline, e.g. plotting programs, may calculate an array of points to be fed to an instance of cubic Spline that should lie between the limits initially supplied to the instance but which, due to rounding errors in the calculation of the array, may have extreme values that lie outside the limits by the an amount equal to the rounding error, e.g. an array that should lie between limits of 0 and 4 may run from 0 to 4.0000000000000003. The default option of the PolyCubicSpline class is to check for such violations of the order of a rounding error and round the extreme value to the limit thus preventing an out of range exception being thrown. This method allows this default option to be ignored so that an out of range exception is thrown if any value lies outside he range of the limis no matter how small the violation is.

public static void potentialRoundingError(double potentialRoundingError)
Usage:                      PolyCubicSpline.potentialRoundingError(potentialRoundingError);
Seveveral applications that call PolyCubicSpline, e.g. plotting programs, may calculate an array of points to be fed to an instance of cubic Spline that should lie between the limits initially supplied to the instance but which, due to rounding errors in the calculation of the array, may have extreme values that lie outside the limits by the an amount equal to the rounding error, e.g. an array that should lie between limits of 0 and 4 may run from 0 to 4.0000000000000003. The default option of the PolyCubicSpline class is to check for such violations of the order of a rounding error and round the extreme value to the limit thus preventing an out of range exception being thrown. The default calculculation of the potential rounding error is the multiplication of 5x10-15 by 10 raised to the exponent of the variable lying outside the limits. This method allows the value of 5x10-15 to be reset to the user's choice, potentialRoundingError.



EXAMPLE PROGAM

An example program may be found on PolyCubicSplineExample.java



OTHER CLASSES USED BY THIS CLASS

This class uses the following classes in this library:


This page was prepared by Dr Michael Thomas Flanagan