SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.curvefit.interpolation.univariate

Class CubicSpline

• java.lang.Object
• com.numericalmethod.suanshu.analysis.curvefit.interpolation.univariate.CubicSpline
• All Implemented Interfaces:
CurveFitting, Interpolation

public class CubicSpline
extends Object
implements Interpolation
The cubic spline interpolation fits a cubic polynomial between each pair of adjacent points such that adjacent cubics are continuous in their first and second derivatives.

Various common end conditions are implemented: natural, clamped, and not-a-knot.

With the given end condition, this implementation also provides a default linear extrapolation at two ends whose slope matches the slope of the first or last splines. That means, the second derivative at both ends are zero.

Wikipedia: Spline interpolation
• Constructor Summary

Constructors
Constructor and Description
CubicSpline()
Creates an instance with default end conditions which fits natural splines, meaning that the second derivative at both ends are zero.
• Method Summary

All Methods
Modifier and Type Method and Description
static CubicSpline clamped()
Creates an instance with end conditions which fits clamped splines, and the first derivative at both ends are zero.
static CubicSpline clamped(double df1, double dfn)
Creates an instance with end conditions which fits clamped splines, meaning that the first derivative at both ends equal to the given values.
UnivariateRealFunction fit(OrderedPairs pairs)
Fit a real valued function from a discrete set of data points.
static CubicSpline natural()
Creates an instance with end conditions which fits natural splines, meaning that the second derivative at both ends are zero.
static CubicSpline notAKnot()
Creates an instance with end conditions which fits not-a-knot splines, meaning that continuity of the third derivative at the second and the next-to-last knots are forced.
• Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• Constructor Detail

• CubicSpline

public CubicSpline()
Creates an instance with default end conditions which fits natural splines, meaning that the second derivative at both ends are zero.
• Method Detail

• natural

public static CubicSpline natural()
Creates an instance with end conditions which fits natural splines, meaning that the second derivative at both ends are zero.
Returns:
the instance
• clamped

public static CubicSpline clamped()
Creates an instance with end conditions which fits clamped splines, and the first derivative at both ends are zero.
Returns:
the instance
• clamped

public static CubicSpline clamped(double df1,
double dfn)
Creates an instance with end conditions which fits clamped splines, meaning that the first derivative at both ends equal to the given values.
Parameters:
df1 - the first derivative at the first point
dfn - the first derivative at the last point
Returns:
the instance
• notAKnot

public static CubicSpline notAKnot()
Creates an instance with end conditions which fits not-a-knot splines, meaning that continuity of the third derivative at the second and the next-to-last knots are forced.
Returns:
the instance
• fit

public UnivariateRealFunction fit(OrderedPairs pairs)
Description copied from interface: Interpolation
Fit a real valued function from a discrete set of data points.

The interpolated function must pass through all the given points.

Specified by:
fit in interface CurveFitting
Specified by:
fit in interface Interpolation
Parameters:
pairs - a discrete set of data points
Returns:
the interpolated function