Main Content

Curve Fitting Toolbox Splines and MATLAB Splines

Curve Fitting Toolbox Splines

Curve Fitting Toolbox™ spline functions contain versions of the essential MATLAB® programs of the B-spline package (extended to handle also vector-valued splines) as described in A Practical Guide to Splines, (Applied Math. Sciences Vol. 27, Springer Verlag, New York (1978), xxiv + 392p; revised edition (2001), xviii+346p), hereafter referred to as PGS. The toolbox makes it easy to create and work with piecewise-polynomial functions.

The typical use envisioned for this toolbox involves the construction and subsequent use of a piecewise-polynomial approximation. This construction would involve data fitting, but there is a wide range of possible data that could be fit. In the simplest situation, one is given points (ti,yi) and is looking for a piecewise-polynomial function f that satisfies f(ti) = yi, all i, more or less. An exact fit would involve interpolation, an approximate fit might involve least-squares approximation or the smoothing spline. But the function to be approximated may also be described in more implicit ways, for example as the solution of a differential or integral equation. In such a case, the data would be of the form (Af)(ti), with A some differential or integral operator. On the other hand, one might want to construct a spline curve whose exact location is less important than is its overall shape. Finally, in all of this, one might be looking for functions of more than one variable, such as tensor product splines.

Care has been taken to make this work as painless and intuitive as possible. In particular, the user need not worry about just how splines are constructed or stored for later use, nor need the casual user worry about such items as “breaks” or “knots” or “coefficients”. It is enough to know that each function constructed is just another variable that is freely usable as input (where appropriate) to many of the commands, including all commands beginning with fn, which stands for function. At times, it may be also useful to know that, internal to the toolbox, splines are stored in different forms, with the command fn2fm available to convert between forms.

At present, the toolbox supports two major forms for the representation of piecewise-polynomial functions, because each has been found to be superior to the other in certain common situations. The B-form is particularly useful during the construction of a spline, while the ppform is more efficient when the piecewise-polynomial function is to be evaluated extensively. These two forms are almost exactly the B-representation and the pp representation used in A Practical Guide to Splines.

But, over the years, the Curve Fitting Toolbox spline functions have gone beyond the programs in A Practical Guide to Splines. The toolbox now supports the `scattered translates' form, or stform, in order to handle the construction and use of bivariate thin-plate splines, and also two ways to represent rational splines, the rBform and the rpform, in order to handle NURBS.

Splines can be very effective for data fitting because the linear systems to be solved for this are banded, hence the work needed for their solution, done properly, grows only linearly with the number of data points. In particular, the MATLAB sparse matrix facilities are used in the Curve Fitting Toolbox spline functions when that is more efficient than the toolbox's own equation solver, slvblk, which relies on the fact that some of the linear systems here are even almost block diagonal.

All polynomial spline construction commands are equipped to produce bivariate (or even multivariate) piecewise-polynomial functions as tensor products of the univariate functions used here, and the various fn... commands also work for these multivariate functions.

There are various examples, all accessible through the Help browser. You are strongly urged to have a look at some of them, or at the splinetool, to help you work with splines.


Consider the set


of all (scalar-valued) piecewise-polynomials of order k with breaks ξ1 < ... < ξl + 1 that, for i = 2...l, may have a jump across ξi in its μith derivative but have no jump there in any lower order derivative. This set is a linear space, in the sense that any scalar multiple of a function in S is again in S, as is the sum of any two functions in S.

Accordingly, S contains a basis (in fact, infinitely many bases), that is, a sequence f1,...,fn so that every f in S can be written uniquely in the form


for suitable coefficients aj. The number n appearing here is the dimension of the linear space S. The coefficients aj are often referred to as the coordinates of f with respect to this basis.

In particular, according to the Curry-Schoenberg Theorem, our space S has a basis consisting of B-splines, namely the sequence of all B-splines of the form B(·|tj,...,tj+k), j = 1...n, with the knot sequence t obtained from the break sequence ξ and the sequence µ by the following conditions:

  • Have both ξ1 and ξl + 1 occur in t exactly k times

  • For each i = 2:l, have ξi occur in t exactly k – µi times

  • Make sure the sequence is nondecreasing and only contains elements from ξ

Note the correspondence between the multiplicity of a knot and the smoothness of the spline across that knot. In particular, at a simple knot, that is a knot that appears exactly once in the knot sequence, only the (k – 1)st derivative may be discontinuous.

MATLAB Splines

The MATLAB technical computing environment provides spline approximation via the command spline. If called in the form cs = spline(x,y), it returns the ppform of the cubic spline with break sequence x that takes the value y(i) at x(i), all i, and satisfies the not-a-knot end condition. In other words, the command cs = spline(x,y) gives the same result as the command cs = csapi(x,y) available in the Curve Fitting Toolbox spline functions. But only the latter also works when x,y describe multivariate gridded data. In MATLAB, cubic spline interpolation to multivariate gridded data is provided by the command interpn(x1,...,xd,v,y1,...,yd,'spline') which returns values of the interpolating tensor product cubic spline at the grid specified by y1,...,yd.

Further, any of the Curve Fitting Toolbox spline fn... commands can be applied to the output of the MATLAB spline(x,y) command, with simple versions of the Curve Fitting Toolbox spline commands fnval, ppmak, fnbrk available directly in MATLAB, as the commands ppval, mkpp, unmkpp, respectively.

Expected Background

The Curve Fitting Toolbox spline functions started out as an extension of the MATLAB environment of interest to experts in spline approximation, to aid them in the construction and testing of new methods of spline approximation. These experts should know the material covered in A Practical Guide to Splines.

However, the basic commands for constructing and using spline approximations are set up to be usable with no more knowledge than it takes to understand what it means to, say, construct an interpolant or a least squares approximant to some data, or what it means to differentiate or integrate a function.

With that in mind, there are sections, like Cubic Spline Interpolation, that are meant even for the novice, while sections devoted to a detailed example, like the one on constructing a Chebyshev spline or on constructing and using tensor products, are meant for users interested in developing their own spline commands.

Vector Data Type Support

The Curve Fitting Toolbox spline functions can handle vector-valued splines, i.e., splines whose values lie in Rd. Since MATLAB started out with just one variable type, that of a matrix, there is even now some uncertainty about how to deal with vectors, i.e., lists of numbers. MATLAB sometimes stores such a list in a matrix with just one row, and other times in a matrix with just one column. In the first instance, such a 1-row matrix is called a row-vector; in the second instance, such a 1-column matrix is called a column-vector. Either way, these are merely different ways for storing vectors, not different kinds of vectors.

In this toolbox, vectors, i.e., lists of numbers, may also end up stored in a 1-row matrix or in a 1-column matrix, but with the following agreements.

A point in Rd, i.e., a d-vector, is always stored as a column vector. In particular, if you want to supply an n-list of d-vectors to one of the commands, you are expected to provide that list as the n columns of a matrix of size [d,n].

While other lists of numbers (e.g., a knot sequence or a break sequence) may be stored internally as row vectors, you may supply such lists as you please, as a row vector or a column vector.

Spline Function Naming Conventions

Most of the spline commands in this toolbox have names that follow one of the following patterns:

cs... commands construct cubic splines (in ppform)

sp... commands construct splines in B-form

fn... commands operate on spline functions

..2... commands convert something

..api commands construct an approximation by interpolation

..aps commands construct an approximation by smoothing

..ap2 commands construct a least-squares approximation

...knt commands construct (part of) a particular knot sequence

...dem commands are examples.

Arguments for Curve Fitting Toolbox Spline Functions

For ease of use, most Curve Fitting Toolbox spline functions have default arguments. In the reference entry under Syntax, we usually first list the function with all necessary input arguments and then with all possible input arguments. When there is more than one optional argument, then, sometimes, but not always, their exact order is immaterial. When their order does matter, you have to specify every optional argument preceding the one(s) you are interested in. In this situation, you can specify the default value for an optional argument by using [] (the empty matrix) as the input for it. The description in the reference page tells you the default value for each optional input argument.

As in MATLAB, only the output arguments explicitly specified are returned to the user.


MathWorks® would like to acknowledge the contributions of Carl de Boor to the Curve Fitting Toolbox spline functions. Professor de Boor authored the Spline Toolbox™ from its first release until Version 3.3.4 (2008).

Professor de Boor received the John von Neumann Prize in 1996 and the National Medal of Science in 2003. He is a member of both the American Academy of Arts and Sciences and the National Academy of Sciences. He is the author of A Practical Guide to Splines (Springer, 2001).

Some of the spline function naming conventions are the result of a discussion with Jörg Peters, then a graduate student in Computer Sciences at the University of Wisconsin-Madison.