dichotomie_premiere_dm1.py

Created by frederic-junier

Created on September 15, 2019

641 Bytes

Implémentations de recherches dichotomiques


# Type your text here
def dichotomie(epsilon):
  """Retourne une valeur approchée à
  epsilon près de racine(2) par dichotomie"""
  a = 1
  b = 2
  while b - a > 2 * epsilon:
    m = (a + b) / 2
    if m ** 2 > 2:
      b = m
    else:
      a = m
    print(m,a,b)
  return (a + b) / 2
  
def dichotomie2(n, epsilon):
  """Retourne une valeur approchée à
  epsilon près de racine(n) par dichotomie"""
  b = 0
  while b ** 2 < n:
       b = b + 1
  a = b  - 1
  while b - a > 2 * epsilon:
    m = (a + b) / 2
    if m ** 2 > n:
      b = m
    else:
      a = m
  return (a + b) / 2
  
dichotomie(0.01)
  

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.