Spline Toolbox | ![]() ![]() |
Put together a spline in ppform
Syntax
Description
The command ppmak(...)
puts together a spline in ppform from minimal information, with the rest inferred from that information. fnbrk
provides any or all of the parts of the completed description. In this way, the actual data structure used for the storage of the ppform is easily modified without any effect on the various fn...
commands that use this construct. However, the casual user is not likely to use ppmak
explicitly, relying instead on the various spline construction commands in the toolbox to construct particular splines.
ppmak(breaks,coefs)
returns the ppform of the spline specified by the break information in breaks
and the coefficient information in coefs
. How that information is interpreted depends on whether the function is univariate or multivariate, as indicated by breaks
being a sequence or a cell array.
If breaks
is a sequence, it must be nondecreasing, with its first entry different from its last. Then the function is assumed to be univariate, and the various parts of its ppform are determined as follows:
l
of polynomial pieces is computed as length(breaks)
-1,
and the basic interval is, correspondingly, the interval [breaks(1)
.. breaks(l+1)]
.
d
of the function's target is taken to be the number of rows in coefs
. In other words, each column of coefs
is taken to be one coefficient. More explicitly, coefs(:,i*k+j)
is assumed to contain the j
th coefficient of the (i+1)
st polynomial piece (with the first coefficient the highest and the k
th coefficient the lowest, or constant, coefficient). Thus, with kl
the number of columns of coefs
, the order k
of the piecewise-polynomial is computed as fix(kl/l)
.
After that, the entries of coefs
are reordered, by the command
in order to conform with the internal interpretation of the coefficient array in the ppform for a univariate spline.
If breaks
is a cell array, of length m
, then the function is assumed to be m
-variate (tensor product), and the various parts of its ppform are determined from the input as follows:
m
-vector l has length(breaks{i})-1
as its i
th entry and, correspondingly, the m
-cell array of its basic intervals has the interval [breaks{i}(1).. breaks{i}(end)]
as its i
th entry.
d
of the function's target and the m
-vector k
of (coordinate-wise polynomial) orders of its pieces are obtained directly from the size of coefs
, as follows.
coefs
is an m
-dimensional array, then the function is taken to be
scalar-valued, i.e., d
is 1, and the m
-vector k
is computed as
size(coefs)./l
. After that, coefs
is reshaped by the command
coefs = reshape(coefs,[1,size(coefs)])
.
coefs
is an (m
+1)-dimensional array, then d
is taken to be
size(coefs,1)
, and the i
th entry of k
is computed as
size(coefs,i+1)/l(i)
, i=1:m
.
Then, coefs
is interpreted as an equivalent array of size [d,l(1),k(1),l(2),k(2),...,l(m),k(m)]
, with its (:,i(1),r(1),i(2),r(2),...,i(m),r(m))
th entry the coefficient of
in the local polynomial representation of the function on the (hyper)rectangle with sides
This is, in fact, the internal interpretation of the coefficient array in the ppform of a multivariate spline.
ppmak
prompts you for breaks
and coefs
.
ppmak(breaks,coefs,d)
also puts together the ppform of a spline from the information supplied. But it interprets the entries of coefs
in the internal way.
Specifically, if the function is univariate, then d
is expected to be a positive integer, and coefs
is taken to be of size [d*l,k]
, with l
obtained as length(breaks)-1
, and this determines the order, k
, of the spline. With this, coefs(i*d+j,:)
is taken to be the j
th components of the coefficient vector for the (i+1
)st polynomial piece.
If the function is multivariate, say m
-variate, then there is, offhand, no reason for using this optional third input argument since, even without it, coefs
is interpreted the internal way. For that reason, in this case, d
, if given, must be an (m+1
)-vector specifying the intended size of coefs
. This is important only in the rare case that the input argument 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
, ppmak
would interpret coefs
incorrectly.
Examples
have exactly the same ppform (2-vector-valued, of order 2). But the second command provides the coefficients in the arrangement used internally.
ppmak([0:2],[1:6])
constructs a piecewise-polynomial function with basic interval [0
..2
] and consisting of two pieces of order 3, with the sole interior break 1. The resulting function is scalar, i.e., the dimension d
of its target is 1. The function happens to be continuous at that break since the first piece is , while the second piece is
.
When the function is univariate and the dimension d
is not explicitly specified, then it is taken to be the row number of coefs
. The column number should be an integer multiple of the number l
of pieces specified by breaks
. For example, the statement ppmak([0:2],[1:3;4:6])
leads to an error, since the break sequence [0:2]
indicates two polynomial pieces, hence an even number of columns are expected in the coefficient matrix. The modified statement ppmak([0:1],[1:3;4:6])
specifies the parabolic curve
. In particular, the dimension
d
of its target is 2. The differently modified statement ppmak([0:2],[1:4;5:8])
also specifies a planar curve (i.e., d
is 2
), but this one is piecewise linear; its first polynomial piece is .
Explicit specification of the dimension d
leads, in the univariate case, to a different interpretation of the entries of coefs
. Now the column number indicates the polynomial order of the pieces, and the row number should equal d
times the number of pieces. Thus, the statement ppmak([0:2],[1:4;5:8],2)
is in error, while the statement ppmak([0:2],[1:4;5:8],1)
specifies a scalar piecewise cubic whose first piece is
.
Finally, if you want to construct a 2-vector-valued bivariate polynomial on the rectangle [-1 .. 1] x [0 .. 1], linear in the first variable and constant in the second, say
will fail, producing a scalar-valued function of order 2 in each variable, as will
while the following command will succeed:
See ppalldem
for other examples.
See Also
fnbrk
, ppalldem
![]() | optknt | rpmak, rsmak | ![]() |