%Interpolation
%Sample2_3
%Different types of interpolation for the same input data
%Matlab function: interp1
%additional function: polyinterp

x = 1:6;
y = [16 18 21 17 15 12];

Type{1} = 'linear';
Type{2} = 'polinomial';
Type{3} = 'pchip';
Type{4} = 'spline';

for k = 1:4
    
    u = linspace(min(x)-0.1, max(x)+0.1, 100);
    if k ~= 2
        v = interp1(x, y, u, Type{k});
    else
        v = polyinterp(x, y, u);
    end

    subplot(2,2,k);
    plot(x, y, 'o', u, v, '-r');
    axis([min(x)-0.5, max(x)+0.5, 0.9*min(y), 1.05*max(y)]);
    title([Type{k} ' interpolation']);
    grid on
end
