home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 5.ddi / SPLINES.DI$ / FNCMB.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.5 KB  |  46 lines

  1. function fn = fncmb(fn1,fnorsc,fn2,sc2)
  2. %FNCMB    Form weighted sum of two splines or two pp's.
  3. %
  4. %        fn = fncmb(fn1,fnorsc[,fn2[,sc2]])
  5. %
  6. % fncmb(function, scalar )  is the function multiplied by the scalar
  7. % fncmb(function,function)  is the sum of the two functions
  8. % fncmb(function,scalar,function)  is the scalar multiple of the first 
  9. %                           function added to the second
  10. % fncmb(function,scalar,function,scalar)  is the linear combination of
  11. %                           the functions with the given scalar weights
  12.  
  13. % C. de Boor / 4 mar 92
  14. % Copyright (c) 1990-92 by Carl de Boor and The MathWorks, Inc.
  15.  
  16. if (fn1(1)==11) 
  17.    [knots,coefs] = spbrk(fn1);
  18.    if (nargin==2)
  19.       if (length(fnorsc)==1), coefs = coefs*fnorsc;
  20.       else
  21.          [knots2,coefs2] = spbrk(fnorsc); coefs = coefs + coefs2;
  22.       end
  23.    else
  24.       coefs = coefs*fnorsc;
  25.       [knots2,coefs2] = spbrk(fn2); 
  26.       if (nargin==4), coefs2 = coefs2*sc2; end
  27.       coefs = coefs + coefs2;
  28.    end
  29.    fn = spmak(knots,coefs);
  30. elseif (fn1(1)==10)
  31.    [breaks,coefs,l,k,d] = ppbrk(fn1);
  32.    if (nargin==2)
  33.       if (length(fnorsc)==1), coefs = coefs*fnorsc;
  34.       else
  35.          [breaks2,coefs2] = ppbrk(fnorsc); coefs = coefs + coefs2;
  36.       end
  37.    else
  38.       coefs = coefs*fnorsc;
  39.       [breaks2,coefs2] = ppbrk(fn2); 
  40.       if (nargin==4), coefs2 = coefs2*sc2; end
  41.       coefs = coefs + coefs2;
  42.    end
  43.    fn = ppmak(breaks,coefs,d);
  44. else error('The first argument does not appear to be a function.\n')
  45. end
  46.