This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / Add-ons & Links / Standard Packages / NumericalMath /


Most methods of fitting curves to data assume that the fit is one-to-one; that is, for each value of , there is only one value of . For some data, you may want to find a general curve in the plane. This is in general a difficult problem, so the approach of making piecewise fits is useful. These are generally referred to as splines. Note that not all splines interpolate points; some splines use a subset of the points to control the shape of the curve, as in specifying a convex hull using Bezier splines.

Generating a spline.

The SplineFit routine currently supports three types of splines: Cubic, Bezier, and CompositeBezier. A cubic spline as currently implemented is made of piecewise third-order polynomials, with continuity, where the second derivative of each polynomial is zero at the endpoints. This curve interpolates each of the points it is created from.

A Bezier spline, on the other hand, interpolates only the endpoints; the other points control the spline, forming a convex hull.

Finally, a composite Bezier spline is made up of a series of third-order Bezier curves with continuity. It alternates interpolating points and control points.

SplineFit returns a SplineFunction object that represents the piecewise spline. It is a parametric function of one argument, representing a spline curve in the plane. Giving it one numeric argument within the range of the parameterization will evaluate to the pair at that point.

This loads the package.

In[1]:= <<NumericalMath`SplineFit`

Here is a list of points.

In[2]:= pts = {{0,0},{1,2},{-1,3},{0,1},{3,0}};

This generates a cubic spline from pts.

In[3]:= spline = SplineFit[pts, Cubic]


We can evaluate the function at any point on the curve.

In[4]:= spline[1.4]


Here is a graph of the curve.

In[5]:= ParametricPlot[spline[u], {u, 0, 4},
PlotRange -> All, Compiled -> False]


Object returned by SplineFit.

Note that the spline function object returned by SplineFit indicates the type of the spline, and the valid range of the parameter to which the function can be applied. The various internal arguments differ for each type of spline, and are hidden in the standard output format. In the cubic spline, for instance, these internal arguments cache the coefficients of the polynomials that make up the spline.

Here is the internal form of the cubic spline function generated from pts.

In[6]:= InputForm[spline]

Out[6]//InputForm= SplineFunction[Cubic, {0., 4.}, {{0, 0}, {1, 2}, {-1, 3}, {0, 1}, {3, 0}}, {{{0, 111/56, 0, -55/56}, {0, 57/28, 0, -1/28}}, {{1, -27/28, -165/56, 107/56}, {2, 27/14, -3/28, -23/28}}, {{-1, -9/8, 39/14, -37/56}, {3, -3/4, -18/7, 37/28}}, {{0, 69/28, 45/56, -15/56}, {1, -27/14, 39/28, -13/28}}}]