racine_carree.py

Created by schraf

Created on April 04, 2020

554 Bytes

Explications en vidéo ici


def rac1(a,p):
  b = a * 10**(2*p)
  s = 1
  n = 1
  while s < b:
    n += 2    
    s += n
  return (n - 1) / 2 / 10**p
  
def rac2(a,e):
  p, q = 1, a
  while q - p > e:
    m = (p + q) / 2
    #print(m)
    if m * m == a or q - p <= e:
      break
    if m * m > a:
      q = m
    else:
      p = m
  return p
      
def rac3(a,e):
  p, q = 1, a
  while q - p > e:
    print(p, q)
    q = (p + q ) / 2
    p = a / q
  return p  
  
def rac3b(a,e):
 q = a
 while q - a / q > e:
  print(q)
  q = (q + a / q) / 2
 return q