1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
>> help spline
SPLINE Cubic spline data interpolation.
PP = SPLINE(X,Y) provides the piecewise polynomial form of the
cubic spline interpolant to the data values Y at the data sites X,
for use with the evaluator PPVAL and the spline utility UNMKPP.
X must be a vector.
If Y is a vector, then Y(j) is taken as the value to be matched at X(j),
hence Y must be of the same length as X -- see below for an exception
to this.
If Y is a matrix or ND array, then Y(:,...,:,j) is taken as the value to
be matched at X(j), hence the last dimension of Y must equal length(X) --
see below for an exception to this.
YY = SPLINE(X,Y,XX) is the same as YY = PPVAL(SPLINE(X,Y),XX), thus
providing, in YY, the values of the interpolant at XX. For information
regarding the size of YY see PPVAL.
Ordinarily, the not-a-knot end conditions are used. However, if Y contains
two more values than X has entries, then the first and last value in Y are
used as the endslopes for the cubic spline. If Y is a vector, this
means:
f(X) = Y(2:end-1), Df(min(X))=Y(1), Df(max(X))=Y(end).
If Y is a matrix or N-D array with SIZE(Y,N) equal to LENGTH(X)+2, then
f(X(j)) matches the value Y(:,...,:,j+1) for j=1:LENGTH(X), then
Df(min(X)) matches Y(:,:,...:,1) and Df(max(X)) matches Y(:,:,...:,end).
Example:
This generates a sine-like spline curve and samples it over a finer mesh:
x = 0:10; y = sin(x);
xx = 0:.25:10;
yy = spline(x,y,xx);
plot(x,y,'o',xx,yy)
Example:
This illustrates the use of clamped or complete spline interpolation where
end slopes are prescribed. In this example, zero slopes at the ends of an
interpolant to the values of a certain distribution are enforced:
x = -4:4; y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0];
cs = spline(x,[0 y 0]);
xx = linspace(-4,4,101);
plot(x,y,'o',xx,ppval(cs,xx),'-');
Class support for inputs x, y, xx:
float: double, single
See also interp1, pchip, ppval, unmkpp, mkpp, splines (The Spline Toolbox).
Reference page in Help browser
doc spline |
Partager