clf; clear all;
x= [0 2  4  7 12 14 17 18 19  20  21  22];
y= exp(pi*0.5*x); 
xq2 = 0:0.1:22;
s = spline(x,y, xq2); %numerical analysis needs fine x values range xq2.
p1 =polyfit(x,y,1); %best line fit p1(1)*x + p1(2).
p2 = polyfit(x,y,2);%best quadratic 
v = interp1(x,y,xq2); %numerical analysis needs fine x values range xq2.
plot(x,y,'o',xq2,s,'-.m',x,p1(1)*x + p1(2),'+-k',xq2,v,'.-r',x,p2(1)*x.^2 + p2(2)*x + p2(3),'*-g')
legend('Data', 'Spline', 'Linear Best Fit', 'Linear Interpolation', 'Quad. Best Fit', 'Location', 'Best')
title('Curve Fitting')
hold off; 

