Detailed instructions for use are in the User's Guide.
[. . . ] Spline ToolboxTM 3 User's Guide
How to Contact The MathWorks
Web Newsgroup www. mathworks. com/contact_TS. html Technical Support
www. mathworks. com comp. soft-sys. matlab suggest@mathworks. com bugs@mathworks. com doc@mathworks. com service@mathworks. com info@mathworks. com
Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information
508-647-7000 (Phone) 508-647-7001 (Fax) The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site. Spline ToolboxTM User's Guide © COPYRIGHT 19902010 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. [. . . ] csaps(x, y, p, xx, w) is the same as fnval(csaps(x, y, p, [], w), xx). [. . . ] = csaps({x1, . . . , xm}, y, . . . ) provides the ppform of an m-variate tensor-product smoothing spline to data on a rectangular
grid. Here, the first argument is a cell-array, containing the vectors
x1, . . . , xm, of lengths n1, . . . , nm, respectively. Correspondingly, y is an array of size [n1, . . . , nm] (or of size [d, n1, . . . , nm] in case the data are d-valued), with y(:, i1, . . . , im) the given (perhaps noisy) value at the
grid site xl(i1), . . . , xm(im).
In this case, p if input must be a cell-array with m entries or else an m-vector, except that it may also be a scalar or empty, in which case it is taken to be the cell-array whose m entries all equal the p input. The optional second output argument will always be a cell-array with m entries. Further, w if input must be a cell-array with m entries, with w{i} either empty, to indicate the default choice, or else a nonnegative vector of the same size as xi.
Examples
Example 1.
x = linspace(0, 2*pi, 21); y = sin(x)+(rand(1, 21)-. 5)*. 1; pp = csaps(x, y, . 4, [], [ones(1, 10), repmat(5, 1, 10), 0] );
returns a smooth fit to the (noisy) data that is much closer to the data in the right half, because of the much larger error weight there, except for the last data point, for which the weight is zero.
11-22
csaps
pp1 = csaps(x, y, [. 4, ones(1, 10), repmat(. 2, 1, 10)], [], . . . [ones(1, 10), repmat(5, 1, 10), 0]);
uses the same data, smoothing parameter, and error weight but chooses the roughness weight to be only . 2 in the right half of the interval and gives, correspondingly, a rougher but better fit there, except for the last data point, which is ignored. A plot showing both examples for comparison can now be obtained by
fnplt(pp); hold on, fnplt(pp1, 'r--'), plot(x, y, 'ok'), hold off title(['cubic smoothing spline, with right half treated ', . . . 'differently:']) xlabel(['blue: larger error weights; ', . . . 'red dashed: also smaller roughness weights'])
The resulting plot is shown below.
cubic smoothing spline, with right half treated differently: 1. 5
1
0. 5
0
-0. 5
-1
-1. 5
0
1
2 3 4 5 6 blue: larger error weights; red dashed: also smaller roughness weights
7
11-23
csaps
Example 2. This bivariate example adds some uniform noise, from the interval [-1/2 . . 1/2], to values of the MATLAB peaks function on a 51-by-61 uniform grid, obtain smoothed values for these data from csaps, along with the smoothing parameters chosen by csaps, and then plot these smoothed values.
x = {linspace(-2, 3, 51), linspace(-3, 3, 61)}; [xx, yy] = ndgrid(x{1}, x{2}); y = peaks(xx, yy); rand('state', 0), noisy = y+(rand(size(y))-. 5); [smooth, p] = csaps(x, noisy, [], x); surf(x{1}, x{2}, smooth. '), axis off
Note the need to transpose the array smooth. For a somewhat smoother approximation, use a slightly smaller value of p than the one, . 9998889, used above by csaps. The final plot is obtained by the following:
smoother = csaps(x, noisy, . 996, x); figure, surf(x{1}, x{2}, smoother. '), axis off
11-24
csaps
Algorithm
csaps is an implementation of the Fortran routine SMOOTH from PGS.
The default value for p is determined as follows. The calculation of the smoothing spline requires the solution of a linear system whose coefficient matrix has the form p*A + (1-p)*B, with the matrices A and B depending on the data sites x. The default value of p makes p*trace(A) equal (1-p)*trace(B).
See Also
csape, spap2, spaps, tpaps
11-25
cscvn
Purpose Syntax Description
"Natural" or periodic interpolating cubic spline curve
curve = cscvn(points) curve = cscvn(points) returns a parametric variational, or natural, cubic spline curve (in ppform) passing through the given sequence points(:j), j = 1:end. The parameter value t(j) for the jth point is chosen by Eugene Lee's [1] centripetal scheme, i. e. , as accumulated square root of chord length:
i< j
points(:, i + 1) - points (:, i)
2
If the first and last point coincide (and there are no other repeated points), then a periodic cubic spline curve is constructed. However, double points result in corners.
Examples
The following provides the plot of a questionable curve through some points (marked as circles):
points=[0 1 1 0 -1 -1 0 0; 0 0 1 2 1 0 -1 -2]; fnplt(cscvn(points)); hold on, plot(points(1, :), points(2, :), 'o'), hold off
Here is a closed curve, good for 14 February, with one double point:
c=fnplt(cscvn([0 . 82 . 92 0 0 -. 92 -. 82 0; . 66 . 9 0 . . . -. 83 -. 83 0 . 9 . 66])); fill(c(1, :), c(2, :), 'r'), axis equal
Algorithm
The break sequence t is determined as
t = cumsum([0;((diff(points. '). ^2)*ones(d, 1)). ^(1/4)]). ';
and csape (with either periodic or variational end conditions) is used to construct the smooth pieces between double points (if any).
See Also
csape, fnplt, getcurve, getcurv2
11-26
cscvn
References
[1] E. "Choosing nodes in parametric curve interpolation. " Computer-Aided Design 21 (1989), 363370.
11-27
fn2fm
Purpose Syntax
Convert to specified form
g = fn2fm(f, form) sp = fn2fm(f, 'B-', sconds) fn2fm(f) g = fn2fm(f, form) describes the same function as is described by f, but in the form specified by the string form. Choices for form are 'B-', 'pp', 'BB', 'rB', 'rp', for the B-form, the ppform, the BBform, and the two rational spline forms, respectively.
Description
The B-form describes a function as a weighted sum of the B-splines of a given order k for a given knot sequence, and the BBform (or, Bernstein-Bézier form) is the special case when each knot in that sequence appears with maximal multiplicity, k. The ppform describes a function in terms of its local polynomial coefficients. [. . . ] Explicitly, choose the fj in the above "model" to be
f j ( x) = ( x - xi ) ,
i j
which is an n 1 degree polynomial for each j. fj(xi) = 0 for every i j, but fj(xj) 0 as long as the xi are all distinct. Set aj = yj/fj(xj) so that f(xj) = fj(xj)aj = yj for all j. In spline interpolation, one chooses the fj to be the n consecutive B-splines Bj(x) = B(x|tj, . . . , tj+k), j = 1:n, of order k for some knot sequence t1 t2 . . . [. . . ]