home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / POLYFUN.DI$ / PPVAL.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  913 b   |  43 lines

  1. function v=ppval(pp,xx)
  2. %PPVAL    Evaluate piecewise polynomial.
  3. %
  4. %      v = ppval(pp,xx)
  5. %
  6. %    returns the value of the pp function  pp  at  xx.
  7. %
  8. %    See also MKPP, UNMKPP, SPLINE.
  9.  
  10. %    Carl de Boor 7-2-86
  11. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  12.  
  13. %  if necessary, sort  xx 
  14. [m,n] = size(xx); v=zeros(m,n);
  15. xs=xx(:);ix=length(xs);tosort=0;
  16. if (max(size(find(diff(xs)<0)))>0),
  17.    tosort=1;[xs,indx]=sort(xs);
  18. end
  19.  
  20. %  take apart  pp
  21. [x,c,l,k]=unmkpp(pp);
  22.  
  23. ilow=1;ixs=length(xs);
  24. while ilow<=ixs;
  25.    index=find(x(2:l+1)>xs(ilow));
  26.    if max(size(index))==0,
  27.       j=l;
  28.    else,
  29.       j=index(1);
  30.    end
  31.    if j<l;
  32.       index=find(xs(ilow:ixs)<x(j+1));
  33.       ihigh=ilow-1+index(max(size(index)));
  34.    else,
  35.       ihigh=ixs;
  36.    end
  37.    v(ilow:ihigh)=polyval(c(j,:),xs(ilow:ihigh)-x(j));
  38.    ilow=ihigh+1;
  39. end;
  40.  
  41. if tosort>0,[junk,indx]=sort(indx); v=v(indx);end
  42. v = reshape(v,m,n);
  43.