dichotomie_racine_de_deux.py

Created by elodie-gamot

Created on November 10, 2021

243 Bytes

Algorithme de dichotomie afin de déterminer un encadrement de sqrt(2)


from math import *
  
def encadrement(e):
  a=1
  b=2
  while b-a>e:
    c=(a+b)/2
    if f(a)*f(c)>0:
      a=c
    else:
      b=c
  print("La valeur est comprise entre",a,"et",b)
  
def f(x):
  return x**2-2