Sagot :
Réponse :
Bonjour,
Explications :
def racDicho(f,borne_inf,borne_sup,precision):
# tester les hypothèses
if borne_inf < borne_sup:
a=borne_inf
b=borne_sup
else:
b=borne_inf
a=borne_sup
fa=f(a)
fb=f(b)
if fa*fb >=0:
print ("mauvaises bornes")
return False
epsilon=pow(10,precision)
while abs(a-b)> epsilon:
m=(a+b)/2
fm=f(m)
print (a,f(a),b,f(b),m,fm)
if fm < 0:
a=m
else:
b=m
return m
# main
f=lambda x:x*x-4*x-10
print (racDicho(f,4,6,-1))
print (racDicho(f,-4,-1,-1))