% write data and choose grid
xGrid = [1 5 10 30 50];   % grid points (in sample)
yGrid = log(xGrid);
xOut = 1:50;              % out of sample points
% plot the data points and the function
hold on 
plot(xGrid,yGrid,'ok','DisplayName','data')
plot(xOut,log(xOut),'k','DisplayName','log','Linewidth',1);
% plot the linear interpolating function
plot(xOut,interp1(xGrid,yGrid,xOut),'k--','DisplayName','linear', ...
    'Linewidth',1);
% plot the polynomial interpolating function
poly4 = polyfit(xGrid, yGrid, 4);
plot(xOut,polyval(poly4,xOut),'k:','DisplayName','poly4','Linewidth',1)
legend('location','northwest'); 
grid on
hold off
xlabel('x'); ylabel('f(x)');
