% Script File: Zoom
%plots derivatives of the functions in zoom
% Plots (x-1)^6 near x=1 with increasingly refined scale.
% Evaluation via x^6 - 6x^5 + 15x^4 - 20x^3 + 15x^2 - 6x +1
% leads to severe cancellation.

close all
k=0;
n=100;
x = linspace(0.5, 1.5, 100)';
%y = (x-ones(n,1)).^6;
y = 6*(x-ones(n,1)).^5;
plot(x,y)
pause
figure
for delta = [.1 .01 .005 .001 .0005  .0001 ]
   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);
  %y = (x-ones(n,1)).^6;
  %y = 6*x.^5 -30*x.^4 +60*x.^3 -60*x.^2 + 30*x -6;
  y = 6*(x-ones(n,1)).^5;
   k = k+1;
   subplot(2,3,k)
   plot(x,y,x,zeros(1,n))
   title (sprintf('delta= %6.3f',delta),'HorizontalAlignment','left')
   axis([1-delta 1+delta -max(abs(y)) max(abs(y))])
end

