function slide=ppalldem
%PPALLDEM This is a slideshow file for use with playshow.m and makeshow.m
%   To see it run, type 'playshow ppalldem', 

%   Carl de Boor 01 dec 97, 14jun99, 31jul99
%   Copyright 1987-2000 by C. de Boor and The MathWorks, Inc.
%   $Revision: 1.11 $

if nargout<1,
  playshow ppalldem
else
  %========== Slide 1 ==========
  slide(1).code={
  };
  slide(1).text={
  '',
  '',
  '',
  ['   This is a quick introduction to the   PPFORM  of a spline and ',...
   ' some of its uses.']};
  %========== Slide 2 ==========


  slide(2).code={
   'hold off, sp = spmak([0 1 4 4 6],[2 -1]); pp = sp2pp(sp);',
   'breaks = fnbrk(pp,''b''); coefs = fnbrk(pp,''c'');',
   'coefs(3,[1 2]) = [0 1]; pp = ppmak(breaks,coefs,1);',
   'fnplt(pp,[breaks(1)-1 breaks(2)],''g'',1.8), hold on,',
   'fnplt(pp, breaks([2 3]),''b'',1.8)', 
   'fnplt(pp,[breaks(3),breaks(4)+1],''m'',1.8)',
   'lp1 = length(breaks);',
   'xb = repmat(breaks,3,1); yb = repmat([2;-2.2;NaN],1,lp1);',
   'plot(xb(:),yb(:),''r'')',
   'title(''a pp made up of three quadratic polynomials, i.e., l=3=k'')',
   'axis([-1 7 -2.5 2.3])',
   'hold off' };
  slide(2).text={
   ['     A (univariate) piecewise polynomial, or   pp   for short, ' ...
    'is characterized by its BREAK SEQUENCE,   breaks   say, and its ',...
    'COEFFICIENT ARRAY,   coefs  say, of the local power form of its ',...
    'polynomial pieces. The break sequence is assumed to be strictly ',...
    'increasing,     breaks(1) < breaks(2) < ... < breaks(l+1),     ',...
    'with  l  the number of polynomial pieces which make up the pp .'],
   '',
    ['    While these polynomials may be of varying degrees, they are ',...
     'all recorded as polynomials of the same  ORDER  k , i.e., the ',...
     'coefficient array  c  is of size  [l,k] , with  coefs(j,:)  ',...
     'containing the  k  coefficients in the local power form for the ',...
     ' j-th polynomial piece.'],
   ''};

  %========== Slide 3 ==========

  slide(3).code={
   '% previously plotted stuff:',
   'fnplt(pp,[breaks(1)-1 breaks(2)],''g'',1.8), hold on,',
   'fnplt(pp, breaks([2 3]),''b'',1.8)',
   'fnplt(pp,[breaks(3),breaks(4)+1],''m'',1.8)',
   'plot(xb(:),yb(:),''r'')',
   'title(''a pp made up of three quadratic polynomials, i.e., l=3=k'')',
   'axis([-1 7 -2.5 2.3])',
   'hold off' };
  slide(3).text={
   [' With this, the precise description of our  pp  in terms of the ',...
    'break sequence  breaks  and the coefficient array  coefs  is'],
   '       pp(t)  =  polyval( coefs(j,:),  t - breaks(j) )        for   breaks(j) <= t < breaks(j+1)',
   'with',
   '     polyval(a,x)   equal to   a(1)*x^(k-1) + a(2)*x^(k-2) + ... + a(k)*x^0 .',
    '',
    ['  In the above picture,  breaks(1) is  0, and coefs(1,:)  equals ',...
    '[ -1/2  0  0], while breaks(3) is 4, and coefs(3,:) equals  ',...
    '[ 0  1  -1] .'],
   ['For  t  not in [breaks(1) .. breaks(l+1)),  pp(t)  is defined by ',...
    'extending the first, resp. last, polynomial piece.'],
   ''};

  %========== Slide 4 ==========

  slide(4).code={
   '% previously plotted stuff:',
   'fnplt(pp,[breaks(1)-1 breaks(2)],''g'',1.8), hold on,',
   'fnplt(pp, breaks([2 3]),''b'',1.8)',
   'fnplt(pp,[breaks(3),breaks(4)+1],''m'',1.8)',
   'plot(xb(:),yb(:),''r'')',
   'title(''a pp made up of three quadratic polynomials, i.e., l=3=k'')',
   'axis([-1 7 -2.5 2.3])',
   'fn = ppmak( [0 1 4 6],  [1/2 0 0   -1/2 1 1/2   0 1 -1] );',
   'hold off' };
  slide(4).text={
   ['  A pp is usually constructed through a process of interpolation or ',...
    'approximation. But it is also possible to make one up in ppform ',...
    'from scratch, using  ppmak( breaks, coefs ). E.g., the above pp can ',...
    ' be obtained by the statement'],
   '',
   ' >>  fn = ppmak( [0 1 4 6],  [1/2 0 0   -1/2 1 1/2   0 1 -1] );',
   '',
   ['which stores, in  fn , a complete description of this pp function ',...
    ' in the so-called  ppform.'],
   '',
   'Various M-files in the toolbox can operate on this form. Here are some examples.',
   ''};

  %========== Slide 5 ==========

  slide(5).code={
   '% previously plotted stuff:',
   'fnplt(pp,[breaks(1)-1 breaks(2)],''g'',1.8), hold on,',
   'fnplt(pp, breaks([2 3]),''b'',1.8)',
   'fnplt(pp,[breaks(3),breaks(4)+1],''m'',1.8)',
   'plot(xb(:),yb(:),''r'')',
   'title(''a pp made up of three quadratic polynomials, i.e., l=3=k'')',
   'axis([-1 7 -2.5 2.3])',
   'hold off' };
  slide(5).text={
   'Evaluation:',
   '',
   '>>  fnval( fn , -1:7 )',
   '',
   'ans = .5  0  .5  1 .5  -1  0  1  2',
   '',
   ''};

  %========== Slide 6 ==========

  slide(6).code={
   '% previously plotted stuff:',
   'fnplt(pp,[breaks(1)-1 breaks(2)],''g'',1.8), hold on,',
   'fnplt(pp, breaks([2 3]),''b'',1.8)',
   'fnplt(pp,[breaks(3),breaks(4)+1],''m'',1.8)',
   'plot(xb(:),yb(:),''r'')',
   'axis([-1 7 -2.5 2.3])',
   'dfn = fnder ( fn );   fnplt( dfn , ''jumps'',''y'', 3)',
   'title('' a pp and its first derivative'')',
   'hold off' };
  slide(6).text={
   'Differentiation:',
   '',
   '>>  dfn = fnder ( fn );   fnplt( dfn , ''jumps'', ''y'', 3)',
   '',
   'Note that  the derivative is continuous at 1 but discontinuous at  4 .',
   ['Also note that, by default,  fnplt  plots a ppform on its BASIC ',...
    'INTERVAL, i.e., on the interval  [ breaks(1)  ..  breaks(end) ] .'],
   ''};

  %========== Slide 7 ==========

  slide(7).code={
   '% previously plotted stuff:',
   'fnplt(pp,[breaks(1)-1 breaks(2)],''g'',1.8), hold on,',
   'fnplt(pp, breaks([2 3]),''b'',1.8)',
   'fnplt(pp,[breaks(3),breaks(4)+1],''m'',1.8)',
   'plot(xb(:),yb(:),''r'')',
   'axis([-1 7 -2.5 2.3])',
   'fnplt( dfn ,''j'',''y'', 3, [-1,7])',
   ' ddfn = fnder( fn, 2 );',
   'fnplt( ddfn ,''j'', ''k'', 1.6, [-1,7])',
   'title(''a pp and its first derivative, and its second derivative'')',
   'hold off' };
  slide(7).text={
   'Differentiation (continued):',
   '',
   '>> ddfn = fnder( fn, 2 );  fnplt( ddfn , ''j'', ''k'', 1.6, [-1,7])',
   '',
   'The second derivative is piecewise constant.',
   '',
   ['Note that this differentiation is done separately for each ',...
    'polynomial piece. E.g., although the first derivative has a ',...
    'jump discontinuity across 4 , the second derivative is not ',...
    'infinite there.  This has consequences when we integrate the ',...
    ' second derivative.']};

  %========== Slide 8 ==========

  slide(8).code={
   '% previously plotted stuff:',
   'fnplt(pp,[breaks(1)-1 breaks(2)],''g'',1.8), hold on,',
   'fnplt(pp, breaks([2 3]),''b'',1.8)',
   'fnplt(pp,[breaks(3),breaks(4)+1],''m'',1.8)',
   'plot(xb(:),yb(:),''r'')',
   'axis([-1 7 -2.5 2.3])',
   'fnplt( dfn , ''j'', ''y'', 3, [-1,7])',
   'fnplt( ddfn ,''j'', ''k'', 1.6, [-1,7])',
   'iddfn = fnint (ddfn);',
   'fnplt( iddfn, .5, [-1,7])',
   'title('' ... and the integral of its second derivative'')',
   'hold off' };
  slide(8).text={
   'Integration:',
   '',
   'iddfn = fnint (ddfn);  fnplt( iddfn, ''c'', .5, [-1,7])',
   '',
   ['Note that integration of the second derivative does recover the ',...
    'first derivative, -- except for the jump across 4 which cannot ',...
    'be recovered since the integral of any pp function is continuous.'],
   ''};

  %========== Slide 9 ==========

  slide(9).code={
   '% previously plotted stuff:',
   'fnplt(pp,[breaks(1)-1 breaks(2)],''g'',1.8), hold on,',
   'fnplt(pp, breaks([2 3]),''b'',1.8)',
   'fnplt(pp,[breaks(3),breaks(4)+1],''m'',1.8)',
   'plot(xb(:),yb(:),''r'')',
   'axis([-1 7 -2.5 2.3])',
   'breaks = fnbrk( fn, ''breaks'' );',
   'piece2 = fnbrk( fn, 2);',
   'fnplt( piece2, ''r'', 2.5, breaks([2 3])+[-1 .5] )',
   'title('' Its second polynomial piece highlighted'')',
   'hold off' };
  slide(9).text={
   'Parts of a ppform can be obtained with the aid of  fnbrk . For example',
   '>> breaks = fnbrk( fn, ''break'' );',
   'recovers the break sequence of the pp  in  fn , while',
   '>> piece2 = fnbrk( fn, 2);',
   'recovers the second polynomial piece, as this plot confirms:',
   '>> fnplt( piece2, ''r'', 2.5, breaks([2 3])+[-1 .5] )',
   ''};

  %========== Slide 10 ==========

  slide(10).code={
   'square = ppmak( 0:4, [ 1 0  0 1  -1 1   0 0 ; 0 0  1 0   0 1  -1 1 ] );',
   ' fnplt(square,''r'',2), axis([-.5 1.5 -.5 1.5]), axis equal',
   'title(''a vector-valued pp which describes a square'')' };
  slide(10).text={
   ['A  pp  can also be vector-valued, to describe a curve, in 2-space ',...
    'or 3-space. In that case, each local polynomial coefficient is a ',...
    'vector rather than a number, but nothing else about the ppform ',...
    'changes. There is one additional part of the ppform to record this, ',...
    'the DIMENSION (of its target).'],
   '',
   ['For example, here is a 2-vector-valued pp describing the unit square, ',...
    'as its plot shows:'],
   '>> square = ppmak( 0:4, [ 1 0  0 1  -1 1   0 0 ; 0 0  1 0   0 1  -1 1 ] );',
   '>> fnplt(square,''r'',2), axis([-.5 1.5 -.5 1.5]), axis equal',
   '',
   ''};

  %========== Slide 11 ==========

  slide(11).code={
   'hold off',
   'x = 0:4; y=-2:2;',
   's2 = 1/sqrt(2);',
   'clear v',
   'v(3,:,:) = [0 1 s2 0 -s2 -1 0].''*[1 1 1 1 1];',
   'v(2,:,:) = [1 0 s2 1 s2 0 -1].''*[0 1 0 -1 0];',
   'v(1,:,:) = [1 0 s2 1 s2 0 -1].''*[1 0 -1 0 1];',
   'sph = csape({x,y},v,{''clamped'',''periodic''});',
   'fnplt(sph), axis equal, axis off',
   'title(''a sphere described by a bicubic 3-vector-valued spline'')',
   '' };
  slide(11).text={
   ['A pp in this toolbox can also be multivariate, namely a tensor',...
    ' product of univariate pp functions.'],
   ['The ppform of such a multivariate pp  is only slightly more',...
    ' complicated, with  breaks  now a cell-array containing the break',...
    ' sequences for each variable, and  coefs  now a multidimensional array.'], 
   ['It is much harder to make up a non-random such function from',...
    ' scratch, so I won''t try that here, particularly since the toolbox',...
    ' is meant to help with the construction of pp functions from some',...
    ' conditions about them.'],
   ['E.g., the sphere above was constructed with the aid of  csape ,',...
    ' and then displayed by  fnplt .'],
   ''};

  %========== Slide 12 ==========

  slide(12).code={
   '' };
  slide(12).text={
   ['   While the  PPFORM  of a pp is efficient for EVALUATION, the ',...
    'CONSTRUCTION of a pp from some data is usually more efficiently ',...
    'handled by determining first its  B-FORM , i.e., its representation ',...
    'as a linear combination of B-splines.'],
   '',
   'For this, look at the demonstration about the B-form.',
   ''};
end
