Michael Thomas Flanagan's Java Scientific Library

BiCubicSpline Class:     Bicubic Spline Interpolation

     

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

This class contains the constructor and methods for performing an interpolation within a two dimensional array of data points, y = f(x1,x2), using natural bicubic splines

The returned interpolated value is the mean of the values obtained by an interpolation the originally entered two dimensional array of tabulated data function values, y = f(x1,x2), and by an interpolation of the transpose of this two dimensional array, y = f(x2,x1). Methods for returning these two individual interpolated values are available.

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

See BiCubicInterpolation for a two dimensional interpolation that, unlike the bicubic spline interpolation, utilises the cross second derivatives, 2f(x1,x2)/∂x1∂x2.

import directive: import flanagan.interpolation.BiCubicSpline;
Constructor public BiCubicSpline(double[] x1, double[] x2, double[][] y)
Interpolate public double interpolate(double xx1, double xx2)
Return mean, original data and transposed data interpolated values public double[] getInterpolatedValues()
Rounding Error Options public static void noRoundingErrorCheck()
public static void potentialRoundingError(double potentialRoundingError)



CONSTRUCTOR

CONSTRUCTOR
public BiCubicSpline(double[] x1, double[] x2, double[][] y)
Usage:                      BiCubicSpline aa = new BiCubicSpline(x1, x2, y);
Creates an instance of the BiCubicSpline object with its internal data arrays initialised to copies of the values in the x1, x2 and y arrays where y is the tabulated function y = f(x1,x2). The variables x1 and x2 are are one dimensional arrays of type double and y is a two dimensional array of type double. The y elements are ordered as {{f(x1[0],x2[0], . . . f(x1[0],x2[m-1]} {f(x1[1],x2[0] . . . f(x1[1],x2[m-1]} ......{f(x1[n-1],x2[0], . . . f(x1[n-1],x2[m-1]} } where m is the number of x1 values and n is the number of x2 values, i.e. 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++){
              yValues[i][j] = 'read statement' or 'calculation of f(x1, x2)';
       }
}




METHODS

INTERPOLATION
public double interpolate(double xx1, double xx2)
Usage:                      y1 = aa.interpolate(xx1, xx2);
Returns the interpolated value of y, y1, for given values of xx1 and xx2, using 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. This method throws an IllegalArgumentException if xx1 or xx2 is outside the range of the values of x1[] or x2[] supplied to the constructor or if two x1 or x2 values within the y = f(x1,x2) data set are identical.



GET THE INDIVIDUAL INTERPOLATED VALUES USED IN CALCULATING THE MEAN VALUE
public double[] getInterpolatedValues()
Usage:                      values = aa.getInterpolatedValues();
Returns an array of five doubles which contains
for the last interpolation performed on calling the interpolate(xx1, xx2) method.



ROUNDING ERROR OPTIONS
public static void noRoundingErrorCheck()
Usage:                      BiCubicSpline.noRoundingErrorCheck();
Seveveral applications that call BiCubicSpline, 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 BiCubicSpline 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:                      BiCubicSpline.potentialRoundingError(potentialRoundingError);
Seveveral applications that call BiCubicSpline, 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 BiCubicSpline 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 value lying outside the limits. This method allows the value of 5x10-15 to be reset to the user's choice, potentialRoundingError.



EXAMPLE PROGAMS

BiCubicExampleOne

This program uses calculated data and compares the interpolated y values obtained using This example program may be found on BiCubicExampleOne.java

BiCubicExampleTwo

This simple program uses both and BiCubicSpline and BiCubicInterpolation to demonstrate interpolation within a data set of the refractive indices of water tabulated as a function of both wavelength and temperature. This example program may be found on BiCubicExampleTwo.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