spmak
Put together spline in B-form
Syntax
spmak(knots,coefs)
spmak(knots,coefs,sizec)
spmak
sp = spmak(knots,coeffs)
Description
The command spmak(...)
puts together a spline function in
B-form, from minimal information, with the rest inferred from the input. fnbrk
returns all the parts of the
completed description. In this way, the actual data structure used for the storage
of this form is easily modified without any effect on the various
fn...
commands that use this construct.
spmak(knots,coefs)
returns the B-form of
the spline specified by the knot information in knots
and the
coefficient information in coefs
.
The action taken by spmak
depends on whether the function is
univariate or multivariate, as indicated by knots
being a
sequence or a cell array. For the description, let sizec
be
size(coefs)
.
If knots
is a sequence (required to be non-decreasing), then
the spline is taken to be univariate, and its order k
is taken to
be length(knots)-sizec(end)
. This means that each `column'
coefs(:,j)
of coefs
is taken to be a
B-spline coefficient of the spline, hence the spline is taken to be
sizec(1:end-1)
-valued. The basic interval of the B-form is [knots(1)
..
knots(end)
].
Knot multiplicity is held to be ≤ k
. This means that the
coefficient coefs(:,j)
is simply ignored in case the
corresponding B-spline has only one distinct knot, i.e., in case
knots(j)
equals knots(j+k)
.
If knots
is a cell array, of length m
, then
the spline is taken to be m
-variate, and coefs
must be an (r+m
)-dimensional array, – except when the spline is
to be scalar-valued, in which case, in contrast to the univariate case,
coefs
is permitted to be an m
-dimensional
array, but sizec
is reset by
sizec = [1, sizec]; r = 1;
The spline is sizec(1:r)
-valued. This means the output of the
spline is an array with r
dimensions, e.g., if
sizec(1:2) = [2, 3]
then the output of the spline is a 2-by-3
matrix.
The spline is sizec(1:r)
-valued, the i
th
entry of the m
-vector k
is computed as
length(knots{i})
- sizec(r+i)
,
i=1:m
, and the i
th entry of the cell array
of basic intervals is set to [knots{i}(1), knots{i}(end)]
.
spmak(knots,coefs,sizec)
lets you supply
the intended size of the array coefs
. Assuming that
coefs
is correctly sized, this is of concern only in the rare
case that coefs
has one or more trailing singleton dimensions.
For, MATLAB® suppresses trailing singleton dimensions, hence, without this explicit
specification of the intended size of coefs
,
spmak
would interpret coefs
incorrectly.
spmak
prompts you for
knots
and coefs
.
sp = spmak(knots,coeffs)
returns the spline
sp
.
Examples
spmak(1:6,0:2)
constructs a spline function with basic interval
[1. .6], with 6 knots and 3 coefficients, hence of order 6 - 3 = 3.
spmak(t,1)
provides the B-spline B(·|t)
in B-form.
The coefficients may be d
-vectors (e.g., 2-vectors or
3-vectors), in which case the resulting spline is a curve or surface (in R2 or
R3).
If the intent is to construct a 2-vector-valued bivariate polynomial on the rectangle [–1..1] × [0..1], linear in the first variable and constant in the second, say
coefs = zeros([2 2 1]); coefs(:,:,1) = [1 0;0 1];
then the straightforward
sp = spmak({[-1 -1 1 1],[0 1]},coefs);
will result in the error message 'There should be no more knots than
coefficients'
, because the trailing singleton dimension of
coefs
will not be perceived by spmak
,
while proper use of that third argument, as in
sp = spmak({[-1 -1 1 1],[0 1]},coefs,[2 2 1]);
will succeed. Replacing here [2 2 1]
by
size(coefs)
would not work.
See the example “Intro to B-form” for other examples.
Diagnostics
There will be an error return if the proposed knot sequence fails to be
nondecreasing, or if the coefficient array is empty, or if there are not more knots
than there are coefficients. If the spline is to be multivariate, then this last
diagnostic may be due to trailing singleton dimensions in
coefs
.