%
% Least Squares Spline Approximation
%
% To be run AFTER  interp.m  unless last plot statement is modified
%
a = 0;
b = 2*pi;
k = input('Degree of polynomial? ');
k = k + 1; % order = degree + 1
n = input('How many basis functions? ');
knots = augknt( linspace(a,b,n-k+2), k );      % number of knots = n+k
% i = find(knots<pi);
% j = find(knots > pi);
% knots = [knots(i) pi pi pi knots(j)];
m = input('How sample points? (Should be >= n): ');
x = linspace(a,b,m); % Need m function samples
y = target(x);
sp2 = spap2(knots,k,x,y);
x2 = linspace(a,b,100);   % Plot 100 points
y2 = target(x2);
y2t = fnval(sp2,x2);
plot(x2,y2,x2,y2t)          % Plot original and approximation
pause                       % Press any key to continue
plot(xx,yy-yt,x2,y2-y2t)    % Plot errors:  original - interpolant  AND
                            %               original - approximation
