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

  1. % PPALLDEM    Demonstrate form and usage of piecewise polynomials.
  2. % Copyright (c) 1990-92 by Carl de Boor and The MathWorks, Inc.
  3.                                             % latest change: September 28, '90
  4. clc;clg;echo on;home                             
  5. %       A piecewise polynomial, or   pp   for short, is characterized by its
  6. %  b r e a k  sequence,   break   say, and the   c o e f f i c i e n t 
  7. %  array,   coefs   say, of the local power form of its polynomial pieces.
  8. %
  9. %     The break sequence is assumed to be strictly increasing,
  10. %               break(1) < break(2) < ... < break(l+1),
  11. %  with  l  the number of polynomial pieces which make up  pp .
  12. %
  13. %      While these polynomials may be of varying degrees, they are
  14. %  all recorded as polynomials of the same  o r d e r   k , i.e., the
  15. %  coefficient array  c  is of size  (l,k) , with  coefs(j,:)  containing
  16. %  the  k  coefficients in the local power form for the j-th polynomial
  17. %  piece.
  18. pause                    % Touch any key to continue
  19. %
  20. %       With this, the precise description of  pp  in terms of the break
  21. %   sequence  break  and the coefficient array  coefs  is
  22. %   pp(t) = polyval(coefs(j,:),t-break(j))  for   break(j) <= t < break(j+1) ,
  23. %
  24. %  Here,  polyval(a,x)  is the MATLAB function; it returns the number 
  25. %     sum{a(j)x^(k-j):j=1,..,k} = a(1)*x^(k-1) + a(2)*x^(k-2) + ... + a(k)*x^0 .
  26. %
  27. %  For  t not in [break(1),break(l+1)),  pp(t)  is defined by extending the 
  28. % first, resp. last, polynomial piece.  
  29. %
  30. pause                    % Touch any key to continue
  31. %    A pp is usually constructed in some M-file, through a process of
  32. %  interpolation or approximation, or conversion from some other form (e.g.,
  33. %  from a spline), and is output as a single (row) vector. But it is also
  34. %  possible to make one up from scratch, using the statement
  35.  
  36. %           pp=ppmak(breaks,coefs).
  37.  
  38. pause                    % Touch any key to continue
  39.  
  40. %    Let's try that.
  41.  
  42. pp=ppmak([-5:-1],[-22:-11])
  43. echo off;
  44. ttype=10;td=1;tl=4;tbreak=[-5:-1];tk=3;tcoef=[-22:-20;-19:-17;-16:-14;-13:-11];
  45. zcheck(pp-[ttype td tl tbreak tk tcoef(:)']);
  46. % Check also integration and differentiation. 
  47. % Evaluation and taking a piece are checked below.
  48. zcheck(pp-fnder(fnint(pp)));echo on
  49. pause                    % Touch any key to continue
  50.  
  51. %    Back comes this row vector in which you could actually find all those
  52. %  numbers input, since they are all negative and distinct. But you thereby
  53. %  also see some other numbers. In fact, it is not worthwhile to wonder just
  54. %  how the pp is described in this vector.
  55.  
  56. pause                    % Touch any key to continue
  57.  
  58. %    If you really want to know the constituent parts of pp, use
  59. %           [breaks,coefs,l,k]=ppbrk(pp)
  60.  
  61. pause(5);
  62.  
  63. [breaks,coefs,l,k]=ppbrk(pp)
  64. pause                    % ... and there they are. Touch any key to continue
  65. echo off
  66. zcheck(breaks-tbreak);zcheck(coefs-tcoef);zcheck([l k]-[tl tk]);echo on
  67. %    Here are some operations you can perform on  pp.
  68.  
  69. %       v=fnval(pp,x)     evaluates,
  70.  
  71. %       dpp=fnder(pp)     differentiates,
  72.  
  73. %       dpp=fnint(pp)     integrates,
  74.  
  75. %       pj=pppce(pp,j)   pulls out the j-th polynomial piece.
  76.  
  77. %       pc=ppcut(pp,[a b])  pulls out the part relevant for the interval
  78. %                           [a,b] .
  79.  
  80. %       (values = ) fnplt(pp)  plots pp between its extreme breaks.
  81.  
  82. %     For example, here is a plot of the particular pp we just made up.
  83.  
  84. pause                     % Touch any key to continue
  85.  
  86. x=[-55:-5]/10; plot(x,fnval(pp,x),'-.');pause
  87.  
  88.  
  89. %   Here, added to the plot, are the breaklines
  90.  
  91. pause                     % Touch any key to continue
  92.  
  93. yy=axis;hold on;
  94. for j=1:l+1;plot([breaks(j) breaks(j)],yy(3:4));end;pause
  95.  
  96. %   And here is, added to that plot, the plot of its third piece
  97.  
  98. pause                     % Touch any key to continue
  99.  
  100. plot(x,fnval(pppce(pp,3),x));pause
  101. hold off; echo off
  102. zcheck(-14+(x+3).*(-15 + (x+3)*(-16))-fnval(pppce(pp,3),x));echo on
  103.  
  104. %     While the pp-representation of a pp is efficient for evaluation, the
  105. %  c o n s t r u c t i o n  of a pp from some data is usually more
  106. %  efficiently handled by determining first its
  107. %   B - r e p r e s e n t a t i o n , i.e., its representation as a linear
  108. %  combination of B-splines.    For this, look at      spalldemo  .
  109.  
  110. pause                     % Touch any key to finish
  111.