Spline Toolbox | ![]() ![]() |
Syntax
Description
returns the spline spapi(knots,x,y)
(if any) of order
with knot sequence knots
for which
If some of the entries of x
are the same, then this is taken in the osculatory sense. Specifically, assuming that the entries of the vector x
are in nondecreasing order, then the th derivative of
takes, at
x(i)
, the value y(:,i)
, with the vector
knt2mlt(x)
, i.e., is
. Thus
-fold repetition of a site
in
x
corresponds to the prescribing of value and the first derivatives of
at
.
with spapi(k,x,y)
,
k
a positive integer,
merely specifies the desired spline order, k
, in which case aptknt
is used to determine a workable (though not necessarily optimal) knot sequence for the given sites x
. In other words, the command spapi(k,x,y)
has the same effect as the more explicit command spapi(aptknt(x,k),x,y)
.
spapi({kork1,...,korkm},{x1,...,xm},y)
returns the B-form of a tensor-product spline interpolant to gridded data. Here, each korki
is either a knot sequence, or else is a positive integer specifying the polynomial order to be used in the i
th variable, thus leaving it to spapi
to provide a corresponding knot sequence for the i
th variable. Further, y
must be an (m
+1)-
dimensional array, with y(:,i1,...,im)
the datum to be fitted at the site
[x{1}(i1),...,x{m}(im)]
, all i1
, ..., im
, unless the spline is to be scalar-valued, in which case, in contrast to the univariate case, y
is permitted to be an m
-dimensional array.
Examples
spapi([0 0 0 0 1 2 2 2 2],[0 1 1 1 2],[2 0 1 2 -1])
produces the unique cubic spline f on the interval
[0..2] with exactly one interior knot, at 1, that satisfies the five conditions
These include 3-fold matching at 1, i.e., matching there to prescribed values of the function and its first two derivatives.
Since the given values are reordered in concert with the given sites if the latter are not already in nondecreasing order, it is, e.g., possible to carry out interpolation to values y
and slopes s
at the increasing site sequence x
by a quintic spline by the command
with ddy0
and ddy1
values for the second derivative at the endpoints.
As a related example, if the function sin(x)
is to be interpolated at the distinct data sites x
by a cubic spline, and its slope is also to be matched at a subsequence x(s)
, then this can be accomplished by the command
in which a suitable knot sequence is supplied with the aid of aptknt
. In fact, if you wanted to interpolate the same data by quintic splines, simply change the 4
to 6
.
As a final example, here is a bivariate interpolant.
x = -2:.5.2; y = -1:.25:1; [xx, yy] = ndgrid(x,y); z = exp(-(xx.^2+yy.^2)); sp = spapi({3,4},{x,y},z); fnplt(sp)
Algorithm
spcol
is called on to provide the almost-block-diagonal collocation matrix (with repeats in
x
denoting derivatives, as described above), and slvblk
solves the linear system (*), using a block QR factorization.
Gridded data are fitted, in tensor-product fashion, one variable at a time, taking advantage of the fact that a univariate spline fit depends linearly on the values being fitted.
See Also
Limitations
The given (univariate) knots and sites must satisfy the Schoenberg-Whitney conditions for the interpolant to be defined. Assuming the site sequence x
to be nondecreasing, this means that we must have
(with equality possible at knots
(1) and knots
(end
)). In the multivariate case, these conditions must hold in each variable separately.
Cautionary Note
If the (univariate) sequence x
is not nondecreasing, both x
and y
will be reordered in concert to make it so. In the multivariate case, this is done in each variable separately. A positive side effect of this was noted above in the examples.
![]() | spap2 | spaps | ![]() |