title: Finding the root of positive number using newton-raphson-method, R
body: <p>So I have the following function, which finds the root of a function using Newton-raphson method. I think my issue is relatively simple: I want the function to find the <em>square root</em> of a given positive number, using the newton raphson medthod. Help?</p>
  <pre><code># FUNCTION: 
  newton &lt;- function(f, delta = 0.0000001, x_0 = 2, n=1000){
    h = 0.0000001
    i = 1; x1 = x_0
    p = numeric(n)
    while (i &lt;= n) { #while i is less than or equal to n(1000), continue iterations
      df.dx = (f(x_0 + h) - f(x_0)) / h # 
      x1 = (x_0 - (f(x_0) / df.dx)) # output of original guess minus (f(x)/f´(x)) (formula for root finding)
      p[i] = x1 # counts iteration so we don't exceed 1000
      i = i+1 # same as ^
      if (abs(x1 - x_0) &lt; delta) break # if output is less than delta: end iteration. Otherwise continue. (x1-x_0=if new value is below our threshold, stop)
      x_0 = x1
    }
    return(p[1: (i-1)]) #
  }
  
  ############## TEST ###############
  func1 &lt;- function(x){
    x^5 - 7
  }
  
  newton(func1)
  
  #VARIABLES are
  #f = the function we input 
  #delta = the accuracy threashold we are willing to accept 
  #x_0 = our initial guess
  #n = the number of iterations
  #h = the distance from X1 to X0,this value much little ,the root much #closed.
  #abs is a sys
  </code></pre>