function fn = fncmb(fn1,fnorsc,fn2,sc2)
%FNCMB	Form weighted sum of two splines or two pp's.
%
%        fn = fncmb(fn1,fnorsc[,fn2[,sc2]])
%
% fncmb(function, scalar )  is the function multiplied by the scalar
% fncmb(function,function)  is the sum of the two functions
% fncmb(function,scalar,function)  is the scalar multiple of the first 
%                           function added to the second
% fncmb(function,scalar,function,scalar)  is the linear combination of
%                           the functions with the given scalar weights

% C. de Boor / 4 mar 92
% Copyright (c) 1990-92 by Carl de Boor and The MathWorks, Inc.

if (fn1(1)==11) 
   [knots,coefs] = spbrk(fn1);
   if (nargin==2)
      if (length(fnorsc)==1), coefs = coefs*fnorsc;
      else
         [knots2,coefs2] = spbrk(fnorsc); coefs = coefs + coefs2;
      end
   else
      coefs = coefs*fnorsc;
      [knots2,coefs2] = spbrk(fn2); 
      if (nargin==4), coefs2 = coefs2*sc2; end
      coefs = coefs + coefs2;
   end
   fn = spmak(knots,coefs);
elseif (fn1(1)==10)
   [breaks,coefs,l,k,d] = ppbrk(fn1);
   if (nargin==2)
      if (length(fnorsc)==1), coefs = coefs*fnorsc;
      else
         [breaks2,coefs2] = ppbrk(fnorsc); coefs = coefs + coefs2;
      end
   else
      coefs = coefs*fnorsc;
      [breaks2,coefs2] = ppbrk(fn2); 
      if (nargin==4), coefs2 = coefs2*sc2; end
      coefs = coefs + coefs2;
   end
   fn = ppmak(breaks,coefs,d);
else error('The first argument does not appear to be a function.\n')
end
