hold off; n=5; % Plot the original function xi=-5:0.01:5; yi=1./(1+xi.*xi); hold off; plot(xi,yi,'b'); hold on; %Lagrange poly with n (equally spaced) nodes x=-5:10/n:5; y=1./(1+x.*x) a=polyfit(x,y,n); yi=polyval(a,xi); plot(xi,yi,'r') %compute the error at q q=1+sqrt(10) trueval=1/(1+q^2) compval=polyval(a,q) error=abs(trueval-compval)