Michael Thomas Flanagan's Java Scientific Library

CubicSplineFast Class:     Cubic Spline Interpolation (fast version)

     

Last update: 14 January 2010                                                                                                                              Main Page of Michael Thomas Flanagan's Java Scientific Library

This class contains the constructor and methods for performing an interpolation within a one dimensional array of data points, y = f(x), using a natural cubic spline.
This is a stripped down version of CubicSpline in which all the data checking statements and methods have been removed to allow a faster execution time. However the user must ensure that the data array x-values are in ascending order, that there are adequate numbers of data points and that the x-values of the point for which an interpolated y-value is required lie within the bounds of the supplied data.
The decrease in execution time is likely to be most significant in the use of the cubic spline interpolation classes, BiCubicSplineFast and PolyCubicSplineFast which both repeatedly call CubicSplineFast.

import directive: import flanagan.interpolation.CubicSplineFast;

SUMMARY OF CONSTRUCTOR AND METHODS

Constructors public CubicSplineFast(double[] x, double[] y)
public CubicSplineFast(int n)
Interpolate public double interpolate(double xx1)
Set Data public void resetData(double[] x, double[] y)
Array public static CubicSplineFast[] oneDarray(int n, int m)
New CubicSplineFast public static CubicSplineFast zero(int n)



CONSTRUCTORS

STANDARD CONSTRUCTOR
public CubicSplineFast(double[] x, double[] y)
Usage:                      CubicSplineFast aa = new CubicSplineFast(x, y);
Creates an instance of the CubicSplineFast object with its internal data arrays initialised to copies of the values in the x and y arrays where y is the tabulated function, y = f(x). The variables x and y are one dimensional arrays of type double. This is the standard constructor.

CONSTRUCTOR WITH ZERO VALUE DATA ARRAYS
public CubicSplineFast(int n)
Usage:                      CubicSplineFast aa = new CubicSplineFast(n);
Creates an instance of the CubicSplineFast object that will hold an array of data points of length n and with all data arrays initialised to zero. This constructor is required by the related class BiCubicSplineFast.



METHODS

INTERPOLATION
public double interpolate(double xx1)
Usage:                      y1 = aa.interpolate(xx1);
Returns the interpolated value of y, y1, for a given value of xx1, using the y = f(x) data stored in aa by the constructor. This method may be called as often as required. The 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 is outside the range of the values of x[] supplied to the constructor or if two x values within the y = f(x) data set are identical.

RESET THE DATA ARRAYS
public void resetData(double[] x, double[] y)
Usage:                      aa.resetData(xx, yy);
Resets the internal data arrays to copies of the values in the xx and yy arrays. This method is required by the related class, BiCubicSplineFast.



ONE DIMESIONAL ARRAY OF CUBIC SPLINE INSTANCES
public static CubicSplineFast[] oneDarray(int n)
Usage:                      CubicSplineFast[] cc = CubicSplineFast.oneDarray(n);
Creates an array, of length n, of CubicSplineFast instances with all data array values set at zero. This method is used by the related class BiCubicSplineFast.



CREATE A NEW INSTANCE OF CUBIC SPLINE
public static CubicSplineFast zero()
Usage:                      CubicSplineFast cc = CubicSplineFast.zero();
Creates and returns a new instance of a cubic spline object with all data array values set at zero. This method is used by the related class BiCubicSplineFast.



EXAMPLE PROGAM

An example program may be found on CubicSplineFastExample.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