function BetterRectangles()
% Repeatedly makes a rectangle with area A "more square" by replacing
% L with (L+W)/2 and then setting the new W as A/L.

for A = [2 100 900 10000]
% Compute the sqrt(A).
% Display the initial rectangle...
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)
% Now make it successively "more square"...
iteration = 0;
while abs(L-W)>=10*eps*abs(L)
% The new L is the average of the old L and W...
L = (L+W)/2;
% Choose W so that the new rectangle has area A...
W = A/L;
% Display
fill([0 L L 0],[0 0 W W],'y')
iteration = iteration +1;
axis equal off
shg
title(sprintf('iter = %2d relerr = |L-W|/L = %10.3e',iteration,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)
end

z = MySqrt(A);
end