echo off
%CHEBDEM equioscillating spline demo.

%   changes: 28 sep 90; 29sep9; 8aug97
%   Copyright 1987-2000 by C. de Boor and The MathWorks, Inc. 
%   $Revision: 1.10 $

home, close, echo on
% Try the construction of the Chebyshev spline  C_t(x)  as an example.
%
% By definition, for given knot sequence  t  in R^{n+k},  C_t  is the
% unique element of  S_{t,k}  of max-norm 1  which maximally oscillates on
% the interval  [t_k .. t_{n+1}]  and is positive near  t_{n+1} . This means
% that there is a unique strictly increasing  tau in R^n  so that the
% function  C in S_{k,t}  given by  C(tau(i))=(-)^{n-i} , all  i , has
% max-norm 1 on  [t_k .. t_{n+1}] . This implies that  tau(1) = t_k ,
%  tau(n) = t_{n+1} , and that  t_i < tau(i) < t_{k+i} , all i .  In fact,
%  t_{i+1} \le tau(i) \le t_{i+k-1} , all i . This brings up the point
% that the knot sequence is assumed to make such an inequality possible,
% i.e., the elements of  S_{k,t}  are assumed to be continuous.
%
%  In short, the Chebyshev spline  C  looks just like the Chebyshev poly-
% nomial.  It performs similar functions. For example, its extrema  tau
% are particularly good points to interpolate at from  S_{k,t}  since the
% norm of the resulting projector is about as small as can be.
%
     pause                          % touch any key to continue

%   In this example, we try to construct  C  for given knot sequence  t .
%
%   We deal with cubic splines, i.e., with order
k = 4;
%   and use the break sequence
breaks = [0 1 1.1 3 5 5.5 7 7.1 7.2 8];

     pause                          % touch any key to continue

% ... and use simple interior knots, i.e., use the knot sequence
t = augknt( breaks, k ) 

     pause                          % touch any key to continue

% thus getting a spline space of dimension
n = length(t)-k

     pause                          % touch any key to continue

%   As our initial guess for the  tau , we use the knot averages
%
%           tau(i) = (t_{i+1} + ... + t_{i+k-1})/(k-1)
%
% recommended as good interpolation point choices:

     pause                          % touch any key to continue

tau = aveknt(t,k)

     pause                          % touch any key to continue

%  We plot the resulting first approximation to  C :

b = (-ones(1,n)).^[n-1:-1:0];
c = spapi(t,tau,b);
plot(breaks([1 end]),[1 1],'k', breaks([1 end]),[-1 -1],'k'), hold on
grid off, fnplt(c,'r')
title('first approximation to an equioscillating spline'),pause

lw = 1; chebloop
