x=[0 1 2 2.5];
y=[2.5 .5 .5 1.5];
plot(x,y,'o', x,y,':')
axis([ 0 3 0 3]);
legend('Data','Linear Interpolation');
hold on
input('');

% quadratic spline
x1=linspace(0,1);
s1=2.5-2*x1;
x2=linspace(1,2);
s2=4.5-6*x2+2*x2.^2;
x3=linspace(2,2.5);
s3=2*x3-3.5;
plot(x1,s1,'r--',x2,s2,'r--',x3,s3,'r--')
legend('Data','Linear Interpolation','Quadratic spline')
input('');

% cubic spline
s1=2.5 - 2.3636*x1 + .3636*x1.^3;
s2=2.6818- 2.9091*x2 +.5455*x2.^2 + .1818*x2.^3;
s3= 12.8638 - 18.1819*x3 + 8.1818*x3.^2 - 1.0909*x3.^3;
plot(x1,s1,'b-.',x2,s2,'b-.',x3,s3,'b-.')
legend('Data','Linear Interpolation','Quadratic spline','Cubic spline')

