input('Plot the original function'); % more points for a smooth plot xx= linspace(-5,5); yy=1./(1+xx.^2); plot(xx,yy) hold on % try some other possibilites input('Plot the 2nd order polynomial'); x= linspace(-5,5,3); y=1./(1+x.^2); p=polyfit(x,y,2); y2=polyval(p,xx); plot(xx,y2, 'm--') legend('Original', '2nd order', 'Location', 'South') input('Plot the 4th order polynomial'); x= linspace(-5,5,5); y=1./(1+x.^2); p=polyfit(x,y,4); y4=polyval(p,xx); plot(xx,y4, 'k:') legend('Original', '2nd order', '4th order', 'Location', 'South') input('Plot the 6th order polynomial'); x= linspace(-5,5,7); y=1./(1+x.^2); p=polyfit(x,y,6); y6=polyval(p,xx); plot(xx,y6, 'b-.') legend('Original', '2nd order', '4th order', '6th order', 'Location', 'South') % want a polynomial to fit all data points input('Plot a 10th order polynomial fit to 11 points.'); x= linspace(-5,5,11); y=1./(1+x.^2); p=polyfit(x,y,10); y10=polyval(p,xx); plot(xx,y10, 'k') legend('Original', '2nd order', '4th order', '6th order', '10th order', 'Location', 'South')