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

  1. function pp=ppmak(breaks,coefs,d)
  2. % PPMAK    Make a pp.
  3. %
  4. %     pp = ppmak(breaks,coefs[,d])
  5. %
  6. %  puts together a pp function from the breaks and coefficients input or
  7. %  requested. 
  8. %    If  d  is not explicitly given, program expects  coefs(d,(k,l)) ,
  9. %  and infers  l := length(breaks)-1  and then  k := (# cols(coefs))/l .
  10. %    If  d  is explicitly given, program expects  coefs((d,l),k) , and
  11. %  infers  k := # cols(coefs), and  l := (# rows(coefs))/d .
  12.  
  13. % C. de Boor / latest change: June 1, 1989
  14. % Copyright (c) 1990-92 by Carl de Boor and The MathWorks, Inc.
  15.  
  16.  
  17. if (nargin==0);
  18.    breaks=input('Give the (l+1)-vector of breaks  >');  
  19.    coefs=input('Give the (d by (k*l)) matrix of local pol. coefficients  >');
  20. end
  21. if (nargin<3),
  22.    [d,kl]=size(coefs);
  23.    if (d==0),
  24.       error('The coefficient sequence is empty!')
  25.    end
  26.    l=length(breaks)-1;k=fix(kl/l);
  27.    if (k<=0)|(k*l~=kl);
  28.       fprintf('The given number %.0f of polynomial pieces is incompatible',l)
  29.       fprintf(' with the total number %.0f of coefficients supplied!\n',kl)
  30.       error('')
  31.    elseif (~isempty(find(diff(breaks)<0))),
  32.       error('The breakpoint sequence should be nondecreasing!')
  33.    else
  34.       % the pp-format expects coefs in array  (d*l) by k, while the standard
  35.       % input supplies them in an array d by (k*l) . This requires the
  36.       % following shuffling, from  D+d(-1+K + k(-1+L))=D-d +(K-k)d + dkL
  37.       % to  D+d(-1+L + l(-1+K)=D-d +(L-l)d + dlK .
  38.       c=coefs(:);([1-k:0]'*ones(1,l)+k*ones(k,1)*[1:l])';
  39.       coefs=[1-d:0]'*ones(1,kl)+d*ones(d,1)*(ans(:)');
  40.       coefs(:)=c(coefs);
  41.    end
  42. else
  43.    [dl,k]=size(coefs); l = dl/d;
  44.    if (l+1~=length(breaks)|dl~=l*d), 
  45.       error('input arguments have incompatible sizes.'),return,end
  46. end
  47. pp=[10 d l breaks(:)' k coefs(:)'];
  48.