% Script file: Same as before, except using Chebyshev points f=inline('1./(1+12*x.^2)'); %% Example 1: Seven points %First define the points for the polynomial: n=7; xp=cos(((2*(1:n)-1)*pi)./(2*n)); yp=f(xp); %Find the coefficients: [v,c]=newtdd(xp,yp); xx=linspace(-1,1,200); %Pts for f, P yy1=f(xx); yy2=nest(c,xx,xp); plot(xp,yp,'r*',xx,yy1,xx,yy2); legend('Data','f(x)','Polynomial') %% Example 2: 15 Points n=15; xp=cos(((2*(1:n)-1)*pi)./(2*n)); yp=f(xp); %Find the coefficients: [v,c]=newtdd(xp,yp); xx=linspace(-1,1,200); %Pts for f, P yy1=f(xx); yy2=nest(c,xx,xp); plot(xp,yp,'r*',xx,yy1,xx,yy2); axis([-1 1 -1 2]) legend('Data','f(x)','Polynomial') %% Example 3: 25 Points n=25; xp=cos(((2*(1:n)-1)*pi)./(2*n)); yp=f(xp); %Find the coefficients: [v,c]=newtdd(xp,yp); xx=linspace(-1,1,200); %Pts for f, P yy1=f(xx); yy2=nest(c,xx,xp); plot(xp,yp,'r*',xx,yy1,xx,yy2); axis([-1 1 -1 2]) legend('Data','f(x)','Polynomial') %% Error from Example 3: plot(yy1-yy2); title('Error using 25 points: Chebyshev')