Class 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.

    See Also:
    Wikipedia: Spline interpolation
    • Constructor Summary

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

      • CubicSpline

        public CubicSpline()
        Constructs 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()
        Constructs 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()
        Constructs 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)
        Constructs 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()
        Constructs 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 -
        Returns:
        the interpolated function