SHARE
TWEET

sqrt

phillip1882 Jun 4th, 2012 192 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2. def bisection(number):
  3.    a = 1.0
  4.    b = number/2.0
  5.    mid = (a+b)/2
  6.    aprox = number -mid*mid
  7.    while math.fabs(aprox) > 0.0001:
  8.       if aprox < 0:
  9.          b = mid
  10.       else:
  11.          a = mid
  12.       mid = (a+b)/2.0
  13.       aprox = number -mid*mid
  14.    return mid
  15.  
  16. def heron(number):
  17.    aprox = 1.0
  18.    aprox = (aprox +number)/2.0
  19.    while math.fabs(number -aprox*aprox) >0.0001:
  20.       aprox = (aprox +number/aprox)/2.0
  21.    return aprox
  22.  
  23. def newton(number):
  24.    aprox = 1.0
  25.    diff = aprox -number
  26.    while math.fabs(diff) > 0.0001:
  27.       aprox = aprox -(diff)/(2*aprox)
  28.       diff = aprox*aprox -number
  29.    return aprox
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top