# interro_12_2020_dichotomie.py
01| from math import sqrt 02|
03| # la fonction test 04| # teste si f(x) > 2 05|
06| def test(x):
07| u, v = 1, x
08| while u < 2 and v > 2:
09| u, v = sqrt(u*v), (u + v)/2 10| return u >= 2
11|
12| eps, a, b = 1e-14, 1, 4 13|
14| while b-a > eps:
15| c = (a + b)/2 16| if test(c):
17| b = c 18| else:
19| a = c 20|
21| print('a, b: ', a, b) 22|
23| # résultat : 3.352 789 134 742 5
1