clear %% % We use n=3 and n=6 with equally spaced nodes for the function % sin(exp(2x)) over [0,1]. %% f = @(x) sin(exp(2*x)); figure(1) fplot(f, [0,1]) hold on t = linspace(0, 1, 4)'; plot(t, f(t), 'o'); p = polyinterp(t,f(t)); fplot(p, [0,1]) xlabel('x') ylabel('f(x)') title('Interpolation on 4 nodes') grid on legend('f(x)', 'data points', 'p(x)', 'location', 'best') %% figure(2) fplot(f, [0,1]) hold on t = linspace(0, 1, 7)'; plot(t, f(t), 'o'); p = polyinterp(t, f(t)); fplot(p, [0,1]); xlabel('x') ylabel('f(x)') title('Interpolation on 7 nodes') grid on legend('f(x)', 'data points', 'p(x)', 'location', 'best') %% % The curves always intersect at the interpolation nodes.