#Program to find root using Bisection method for f(x)=x-tan(x):
from math import*
def f(x):
y=x-tan(x)
return y
a=input("Enter the lower limit:")
b=input("Enter the upper limit:")
a=float(a)
b=float(b)
while f(a)*f(b)>0:
print("The root for the given function does not lie between the limits.")
a=input("Enter new lower limit:")
b=input("Enter new upper limit:")
a=float(a)
b=float(b)
s=0
while (f(a)*f(b))<0:
c=(a+b)/2.0
if abs(f(c))<0.0000001:
break
if f(a)*f(c)<0:
b=c
else:
a=c
s=s+1
print("the root of the function is=",c,"\nThe required No. of steps:",s)
print("The value of the function at point of root is=",f(c))
from math import*
def f(x):
y=x-tan(x)
return y
a=input("Enter the lower limit:")
b=input("Enter the upper limit:")
a=float(a)
b=float(b)
while f(a)*f(b)>0:
print("The root for the given function does not lie between the limits.")
a=input("Enter new lower limit:")
b=input("Enter new upper limit:")
a=float(a)
b=float(b)
s=0
while (f(a)*f(b))<0:
c=(a+b)/2.0
if abs(f(c))<0.0000001:
break
if f(a)*f(c)<0:
b=c
else:
a=c
s=s+1
print("the root of the function is=",c,"\nThe required No. of steps:",s)
print("The value of the function at point of root is=",f(c))
Comments
Post a Comment