function [x, niters] = mysqroot(a, tol)
%MYSQROOT Newton's zero-finding method for calculating the square root
%         Return converged value x and the number of iterations
      niters = 0;
      xprev = Inf;
      x = a;
      while abs(x - xprev) > tol
         xprev = x;
         x = 0.5*(x + a/x);
         niters = niters + 1;
      end
   end
