%Demo Program for Chapter 4 
%
%Set up a data set for piecewise interpolation
%using parameterized variables
%
close all
clear all
clc
n = 10;
m=200;
xdata = linspace(0,3,n);
%Use the humps function todefine y
ydata = humps(xdata);
%set up fine grid for evaluation:
xexact = linspace(0,3,m);
hold on
subplot(2,1,1);
yexact = humps(xexact);
plot(xexact,yexact,'-k',xdata,ydata,'g*')
title ('exact humps fn')
xlabel('x')
ylabel ('f(x)')
%add a cubic or spline fit to the plot1
X1 = xexact;
Y1 = spline(xdata,ydata,X1);
plot(xexact,yexact,'-k',xdata,ydata,'g*',X1,Y1,'-r')
legend('exact','data pts','interpolant')
title (' Interpolant X,Y')
xlabel('x')
ylabel ('f(x)')
pause
subplot(2,1,2);
%set parameter variable for data set
nptlim = length (xdata);
ndata = [1:nptlim];
ndatafine = linspace(1,nptlim,m);
%spline fits for X2 and Y2 as function of parateter
X2 = spline(ndata,xdata,ndatafine);
Y2 = spline(ndata,ydata,ndatafine);
plot(xexact,yexact,'-k',xdata,ydata,'g*',X2,Y2,'-r')
legend('exact','data pts','param interp')
title ('Parameterized Interpolant X(t),Y(t)')
xlabel('x')
ylabel ('f(x)')
pause
