% Illustration of the runge phenomenon for k = [5,11,25,51,75] shg % bring plot window forward x = linspace(-1,1,k); % generate k nodes (odd number) y = 1 ./ (1 + 25*x.^2); xx = linspace(-1,1,200); % generate many points on curve yr = 1 ./ (1 + 25*xx.^2); p = polyfit(x,y,k-1); % generate points for polynomial yp = polyval(p, xx); yr = 1 ./ (1 + 25*xx.^2); plot(x,y,'o', ... % show k nodes on curve xx,yp,'-', ... % show the degree k-1 polynomial xx,yr,'--') % show the curve with dotted line axis([-1,1,-0.5,2]); input('press enter'); end