% CLASS18NOV  Plot piecewise-linear and polynomial interpolants.

f = @(x) exp(-x) - 0.01 * sin(20*x)

x = 0:0.25:1.5          % 7 = 6+1 points for p_6(x)
x30 = 0:0.05:1.5       % 31 = 30+1 points for p_30(x)
xp = 0:0.001:1.5;

plot(x,f(x),'o',xp,f(xp),x,f(x),...
     xp,polyval(polyfit(x,f(x),6),xp),...
     xp,polyval(polyfit(x30,f(x30),30),xp))

legend('nodes','f(x)','L(x)','p_6(x)','p_{30}(x)')
axis([0 1.5 0.2 1])
