function BetterRectangles()
% Repeatedly makes a rectangle with area A "more square" by replacing
% L with  (L+W)/2.

for A = floor(rand(1,20)*1000)
   z = MySqrt(A);
end
   
   
  function z = MySqrt(A)
% A satisfies 1<=A<=1000
% z satisfies |z-sqrt(A)|<=10*eps*sqrt(A)
L = A;
W = 1;
fill([0 L L 0],[0 0 W W],'y')
axis equal off
title(sprintf('The Initial Rectangle with Area = %1d',A),'fontsize',24)
shg
pause(2)
k = 0;
while abs(L-W)>=10*eps*abs(L)
   L = (L+W)/2;
   W = A/L;
   fill([0 L L 0],[0 0 W W],'y')
   k = k+1;
   axis equal off
   shg
   title(sprintf('iter = %2d    relerr = |L-W|/L  =  %10.3e',k,abs(1-W/L)),'fontsize',24)
   text(0,-L/10,sprintf('sqrt(%1d)  =  %18.15f',A,L),'fontsize',24)
   pause(1.5)
end
pause(3)
z = L;