title: Consider the equation x2−2 = 0. Use Newton’s method to determine an approximation to the positive root starting with x0 = 1
body: <p>Consider the equation x2−2 = 0. Use Newton’s method to determine an approximation to the positive root starting with x0 = 1.</p>
  
  <p>I tried the python, but it is not corrected. Can you tell me where I got wrong</p>
  
  <pre><code> def newton(p,dp,x0,tol = 1e-14,catch = 1000):
          x=x0
          r=-p(x)
  
          iter =0
  
          while abs(r) &gt; tol and iter &lt; catch:
                  d = dp(x)
                  x +=  r/d
                  r = -p(x)
                  iter += 1
          return x, iter
  
  &gt;&gt;&gt; from file import newton
  &gt;&gt;&gt; p = lambda x:x**-2
  &gt;&gt;&gt; dp = lambda x:2*x
  &gt;&gt;&gt; x0=1;tol = 1e-15;maxiter =10
  
  &gt;&gt;&gt; root = newton(p,dp,x0,tol,maxiter)
  &gt;&gt;&gt; print 'root = %.16f in %i iterations' % root
  root = 1.0000000000000000 in 10 iterations
  </code></pre>