title: Solving for the square root by Newton's Method
body: <p><a href="https://i.stack.imgur.com/DGiey.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DGiey.png" alt="enter image description here"></a></p>
  
  <hr>
  
  <p>yinitial = x</p>
  
  <p>y_n approaches sqrt(x) as n->infinity</p>
  
  <p>If theres an x input and tol input. Aslong as the |y^2-x| > tol is true compute the following equation of y=0.5*(y + x/y). How would I create a while loop  that will stop when |y^2-x| &lt;= tol. So every time through the loop the y value changes. In order to get this answer---></p>
  
  <pre><code>&gt;&gt;sqrtx = sqRoot(25,100)
  
  sqrtx =
   7.4615
  </code></pre>
  
  <p>I wrote this so far:</p>
  
  <pre><code>function [sqrtx] = sqrRoot(x,tol)
  
  n = 0;
  x=0;%initialized variables
  
  if x &gt;=tol %skips all remaining code
  
     return
  
  end
  
  while x &lt;=tol
  
      %code repeated during each loop
  
     x = x+1  %counting code
  
  end
  </code></pre>