edu.mines.jtk.util
Class CubicInterpolator

java.lang.Object
  extended by edu.mines.jtk.util.CubicInterpolator

public class CubicInterpolator
extends java.lang.Object

Piecewise cubic interpolation of a function y(x) (or its derivatives).

Piecewise cubic interpolators differ in the method they use to compute slopes y'(x) at specified x (knots). The classic cubic spline computes the slopes to obtain a continuous second derivative at the knots. These splines often yield unacceptable wiggliness (overshoot) between the knots. A linear spline yields no overshoot, but has discontinuous first (and higher) derivatives. A monotonic spline has continuous first derivatives and yields monotonic interpolation (with no overshoot) where function values at the knots are monotonically increasing or decreasing.

For x outside the range of values specified when an interpolator was constructed, the interpolator extrapolates using the cubic polynomial corresponding to the knot nearest to x.

Version:
1998.11.17, 2006.07.12
Author:
Dave Hale, Colorado School of Mines

Nested Class Summary
static class CubicInterpolator.Method
          The method used for piecewise cubic interpolation.
 
Constructor Summary
CubicInterpolator(CubicInterpolator.Method method, int n, float[] x, float[] y)
          Constructs an interpolator.
 
Method Summary
 float interpolate(float x)
          Interpolates a function value y(x).
 void interpolate(int n, float[] x, float[] y)
          Interpolates an array of function values y(x).
 float interpolate1(float x)
          Interpolates the first derivative y'(x).
 void interpolate1(int n, float[] x, float[] y)
          Interpolates an array of first derivatives y'(x).
 float interpolate2(float x)
          Interpolates the second derivative y''(x).
 void interpolate2(int n, float[] x, float[] y)
          Interpolates an array of second derivatives y''(x).
 float interpolate3(float x)
          Interpolates the third derivative y'''(x).
 void interpolate3(int n, float[] x, float[] y)
          Interpolates an array of third derivatives y'''(x).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CubicInterpolator

public CubicInterpolator(CubicInterpolator.Method method,
                         int n,
                         float[] x,
                         float[] y)
Constructs an interpolator.

Parameters:
method - interpolation method: LINEAR, MONOTONIC, or SPLINE.
n - number of x and y(x) values specified.
x - array[n] of values at which y(x) are specified. These values must be monotonically increasing or decreasing, with no equal values. (In other words, the array must be monotonic-definite.)
y - array[n] of function values y(x).
Method Detail

interpolate

public final float interpolate(float x)
Interpolates a function value y(x).

Parameters:
x - value at which to interpolate.
Returns:
interpolated function value y(x).

interpolate1

public final float interpolate1(float x)
Interpolates the first derivative y'(x).

Parameters:
x - value at which to interpolate.
Returns:
interpolated first derivative y'(x).

interpolate2

public final float interpolate2(float x)
Interpolates the second derivative y''(x).

Parameters:
x - value at which to interpolate.
Returns:
interpolated second derivative y''(x).

interpolate3

public final float interpolate3(float x)
Interpolates the third derivative y'''(x).

Parameters:
x - value at which to interpolate.
Returns:
interpolated third derivative y'''(x).

interpolate

public void interpolate(int n,
                        float[] x,
                        float[] y)
Interpolates an array of function values y(x).

Parameters:
n - number of values to interpolate.
x - array of values at which to interpolate.
y - array of interpolated function values.

interpolate1

public void interpolate1(int n,
                         float[] x,
                         float[] y)
Interpolates an array of first derivatives y'(x).

Parameters:
n - number of derivatives to interpolate.
x - array of values at which to interpolate.
y - array of interpolated first derivatives y'(x).

interpolate2

public void interpolate2(int n,
                         float[] x,
                         float[] y)
Interpolates an array of second derivatives y''(x).

Parameters:
n - number of derivatives to interpolate.
x - array of values at which to interpolate.
y - array of interpolated second derivatives y''(x).

interpolate3

public void interpolate3(int n,
                         float[] x,
                         float[] y)
Interpolates an array of third derivatives y'''(x).

Parameters:
n - number of derivatives to interpolate.
x - array of values at which to interpolate.
y - array of interpolated third derivatives y'''(x).