% Script File: Zoom
% Plots (x-1)^6 near x=1 with increasingly refined scale.
% Evaluation via binomial expansion leads to severe cancellation
% (x-1)^6 = x^6 - 6*x^5 + 15*x^4 - 20*x^3 + 15*x^2 -6*x + 1
close all
k = 0; n = 100;
for delta = [.1 .01 .001]
   x = linspace(1-delta,1+delta,n)';
   y = x.^6 - 6*x.^5 + 15*x.^4 - 20*x.^3 + 15*x.^2 -6*x + ones(n,1);
   z = ones(n,1) + x.*(-6 +x.*(15 +x.*(-20 +x.*(15 +x.*(-6+x)))));
   w = (x-1).^6;
   k = k+1; subplot(3,3,k); plot(x,y,x,zeros(1,n))
   axis([1-delta 1+delta -max(abs(y)) max(abs(y))])
   subplot(3,3,k+3); plot(x,z,x,zeros(1,n))
   axis([1-delta 1+delta -max(abs(z)) max(abs(z))])
   subplot(3,3,k+6); plot(x,w,x,zeros(1,n))
   axis([1-delta 1+delta -max(abs(w)) max(abs(w))])
end
