| Spline Toolbox | Search  Help Desk |
| spapi | Examples See Also |
Syntax
spline = spapi(knots,x,y)
Description
Returns the spline f (if any) of orderk = length(knots) - length(x)with knot sequence
knots for which
(*)This is taken in the osculatory sense in case somey(:,i)= f(x(i)), alli
x are repeated, i.e., in the sense that Dm(i)f(x(i)) = y(:,i) in case the x are in nondecreasing order, with m = knt2mlt(x), i.e., m(i) := #{j < i:x(j) = x(i)}. Thus m-fold repetition of a point z in x corresponds to the prescribing of value and the first m - 1 derivatives of f at z.
It is also possible to interpolate to gridded data. If knots is a cell array with m entries, then also x must be a cell array with m entries, and y must be an (m+1)-dimensional array, with y(:,i1,...,im) the datum to be fitted at the m-vector [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 [0..2] with exactly one interior knot, at 1, that satisfies the five conditions
f(0+) = 2, f(1) = 0, Df(1) = 1, D2f(1) = 2, f(2-) = -1
Since the given ordinates are re-ordered in unison with the given abscissae if the latter are not already in decreasing order, it is, e.g., possible to carry out interpolation to values y and slopes s at the increasing point sequence x by a quintic spline by the command
sp = spapi(augknt(x,6,2),[x x x([1 end])],[y,s,ddy0,ddy1]);with
ddy0 and ddy1 values for the second derivative.
Algorithm
spcol is called on to provide the almost-block-diagonal collocation matrix (Bj,k(x)) (with repeats in x denoting derivatives, as described above), and slvblk solves the linear system (*), using a block QR factorization.
Gridded data are fitted 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
spaps, spap2, csapi, spline
Limitations
The given (univariate) knots and abscissae must satisfy the Schoenberg-Whitney conditions for the interpolant to be defined. Assuming the abscissa sequencex to be nondecreasing, this means that we must have
knots(j) <(with equality possible atx(j) < knots(j+k), all j
knots(1) and knots(n+k)). In the multivariate case, these conditions must hold in each variable separately.
Cautionary Note
If the(univariate) sequencex 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.