Main Content

fncmb

Arithmetic with function(s)

Syntax

fn = fncmb(function,operation)
f = fncmb(function,function)
fncmb(function,matrix,function)
fncmb(function,matrix,function,matrix)
f = fncmb(function,op,function)

Description

The intent is to make it easy to carry out the standard linear operations of scaling and adding within a spline space without having to deal explicitly with the relevant parts of the function(s) involved.

fn = fncmb(function,operation) returns (a description of) the function obtained by applying to the values of the function in function the operation specified by operation. The nature of the operation depends on whether operation is a scalar, a vector, a matrix, or a character vector or string scalar, as follows.

Scalar

Multiply the function by that scalar.

Vector

Add that vector to the function's values; this requires the function to be vector-valued.

Matrix

Apply that matrix to the function's coefficients.

Character vector or string scalar

Apply the function specified by that character vector or string scalar to the function's coefficients.

The remaining options only work for univariate functions. See Limitations for more information.

f = fncmb(function,function) returns (a description of) the pointwise sum of the two functions. The two functions must be of the same form. This particular case of just two input arguments is not included in the above table since it only works for univariate functions.

fncmb(function,matrix,function) is the same as fncmb(fncmb(function,matrix),function).

fncmb(function,matrix,function,matrix) is the same as fncmb((fncmb(function,matrix),fncmb(function,matrix))).

f = fncmb(function,op,function) returns the ppform of the spline obtained by the pointwise combining of the two functions, as specified by the character vector or string scalar op. The argument op can be one of '+', '-', or '*'. If the second function is to be a constant, it is sufficient simply to supply here that constant.

Examples

fncmb(fn,3.5) multiplies (the coefficients of) the function in fn by 3.5.

fncmb(f,3,g,-4) returns the linear combination, with weights 3 and –4, of the function in f and the function in g.

fncmb(f,3,g) adds 3 times the function in f to the function in g.

If the function f in f happens to be scalar-valued, then f3=fncmb(f,[1;2;3])contains the description of the function whose value at x is the 3-vector (f(x), 2f(x), 3f(x)). Note that, by the convention throughout this toolbox, the subsequent statement fnval(f3, x) returns a 1-column-matrix.

If f describes a surface in R3, i.e., the function in f is 3-vector-valued bivariate, then f2 = fncmb(f,[1 0 0;0 0 1]) describes the projection of that surface to the (x, z)-plane.

The following commands produce the picture of a ... spirochete?

c = rsmak('circle');
fnplt(fncmb(c,diag([1.5,1]))); axis equal, hold on
sc = fncmb(c,.4);
fnplt(fncmb(sc,-[.2;-.5]))
fnplt(fncmb(sc,-[.2,-.5]))
hold off, axis off

If t is a knot sequence of length n+k and a is a matrix with n columns, then fncmb(spmak(t,eye(n)),a) is the same as spmak(t,a).

fncmb(spmak([0:4],1),'+',ppmak([-1 5],[1 -1])) is the piecewise-polynomial with breaks -1:5 that, on the interval [0 .. 4], agrees with the function x|→ B(x|0,1,2,3,4) + x (but has no active break at 0 or 1, hence differs from this function outside the interval [0 .. 4]).

fncmb(spmak([0:4],1),'-',0) has the same effect as fn2fm(spmak([0:4],1),'pp').

Assuming that sp describes the B-form of a spline of order <k, the output of

 fn2fm(fncmb(sp,'+',ppmak(fnbrk(sp,'interv'),zeros(1,k))),'B-')

describes the B-form of the same spline, but with its order raised to k.

Limitations

fncmb only works for univariate functions, except for the case fncmb(function,operation), i.e., when there is just one function in the input.

Further, if two functions are involved, then they must be of the same type. This means that they must either both be in B-form or both be in ppform, and, moreover, have the same knots or breaks, the same order, and the same target. The only exception to this is the command of the form fncmb(function,op,function).

Algorithms

The coefficients are extracted (via fnbrk) and operated on by the specified matrix or operation (and, possibly, added), then recombined with the rest of the function description (via ppmak, spmak,rpmak,rsmak,stmak). To be sure, when the function is rational, the matrix is only applied to the coefficients of the numerator. Again, if we are to translate the function values by a given vector and the function is in ppform, then only the coefficients corresponding to constant terms are so translated.

If there are two functions input, then they must be of the same type (see Limitations, below) except for the following.

fncmb(f1,op,f2) returns the ppform of the function

x|f1(x) op f2(x)

with op one of '+', '-', '*', and f1, f2 of arbitrary polynomial form. If, in addition, f2 is a scalar or vector, it is taken to be the function that is constantly equal to that scalar or vector.