| Spline Toolbox | ![]() |
General Spline Interpolation
If you want to interpolate at sites other than the breaks and/or by splines other than cubic splines with simple knots, then you use the spapi command. In its simplest form, you would say
in which the first argument, k, specifies the order of the interpolating spline; this is the number of coefficients in each polynomial piece, i.e., 1 more than the nominal degree of its polynomial pieces. For example, the next figure shows a linear, a quadratic, and a quartic spline interpolant to our data, as obtained by the statements
sp2 = spapi(2,x,y); fnplt(sp2), hold on sp3 = spapi(3,x,y); fnplt(sp3,'--') sp5 = spapi(5,x,y); fnplt(sp5,'-.'), plot(x,y,'o') legend('linear','quadratic','quartic','data'), hold off
Figure 2-2: Spline Interpolants of Various Orders to Smooth Data
Even the cubic spline interpolant obtained from spapi is different from the one provided by csapi and spline. To emphasize their difference, we compute and plot their second derivatives, as follows:
fnplt(fnder(spapi(4,x,y),2)), hold on fnplt(fnder(csapi(x,y),2),1.5),plot(x,zeros(size(x)),'o') legend('from spapi','from csapi','data sites'), hold off
This gives the following graph:
Figure 2-3: Second Derivative of Two Cubic Spline Interpolants to the Same Smooth Data
Since the second derivative of a cubic spline is a broken line, with vertices at the breaks of the spline, we can see clearly that csapi places breaks at the data sites, while spapi does not, and thereby produces a less jerky second derivative in this example.
| Other End Conditions | Knot Choices | ![]() |