# Bisection method
def f(x):
return (x**2-2)
e=0.00001
a=float(input('Enter limit a '))
b=float(input('Enter limit b '))
if f(a)*f(b)<=0.0:
while abs(a-b)>=e:
x=(a+b)/2
if(f(x)*f(a)>0):
a=x
else:
b=x
print'The best approximation is %.5f'%x
else:
print' sorry !!! There is no root between',a,'and ',b
No comments:
Post a Comment