% CHEBDEM	Demonstrate the construction of a Chebyshev spline.
% Copyright (c) 1990-92 by Carl de Boor and The MathWorks, Inc.
                                     % latest change: September 28, 1990
clg;clc;home;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]; lb=length(breaks);

     pause;                          % touch any key to continue

% and use simple interior knots, i.e., use the knot sequence
t = breaks([ones(1,k) 2:lb-1  lb*ones(1,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)
echo off
e=zcheck(tau-[0 10 21 51 91 135 175 196 213 223 232 240]/30); echo on

     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);
echo off;
e=zcheck(b-fnval(c,tau));echo on;
fnplt(c,'-.');pause
grid;pause
hold on;

chebloop
