% square_root.m
% Carry out an iteration to estimate the square root of a number.
%
%  We require X*Y = Z
%  and we try to "encourage" x=y.
%
z = input ( '  Enter Z, whose square root is desired:' );
%
%  Initialize, so that X*Y = Z
%
x = z;
y = z / x;
%
%  Repeat the following steps 10 times.
%
for i = 1 : 10
%
%  Replace X and Y by average.
%  Set Y so that it's still true that X*Y = Z.
%
  x = ( x + y ) / 2.0;
  y = z / x;

end
%
%  Print final x, y, z, and sqrt(z), probably not good since we didn't take many steps.
%
fprintf ( '  %g * %g = %g, exact square root is %g\n', x, y, z, sqrt ( z ) );

