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

  1. function sp=spap2(knots,k,x,y)
  2. % SPAP2    Least-squares approximation by splines.
  3. %
  4. %         spap2(knots,k,x,y)
  5. %
  6. %  returns the spline  f  of order  k  with knot sequence  knots  for which
  7. %
  8. %  (*)                y = f(x) 
  9. %
  10. % in the mean-square sense. If the abscissae satisfy the conditions
  11. %
  12. %  (**)   knots(j) < x(j) < knots(j+k) , j=1,...,length(x)=length(knots)-k ,
  13. %
  14. %  f  is the unique spline of that order satisfying  (*)  exactly.
  15. % No spline is returned unless (**) is satisfied for some subsequence of  x .
  16.  
  17. % C. de Boor / latest change: December 24, 1989
  18. % Copyright (c) 1990-92 by Carl de Boor and The MathWorks, Inc.
  19.  
  20.  
  21. % It is assumed that  y  has the same sense as  x  which is important in case
  22. % the entries of  y  are vectors rather than scalars
  23. [rx,cx]=size(x); [ry,cy]=size(y);
  24. if (rx>1),
  25.    if (ry~=rx), error(' y  should contain exactly as many entries as  x ')
  26.    else, y=y';end
  27. else,
  28.    if (cy~=cx), error(' y  should contain exactly as many entries as  x ')
  29.    end
  30. end
  31.  
  32. %  sort the given abscissae.
  33. [x,index]=sort(x);y=y(:,index);
  34.  
  35. %  Generate the collocation matrix and divide it into the possibly reordered
  36. %  sequence of given ordinates to generate the B-spline coefficients of the 
  37. %  interpolant, then put it all together into  sp .
  38.  
  39. sp=spmak(knots,slvblk(spcol(knots,k,x,1),y')');
  40.