#Program to find root using Bisection method for y=x-3(1-exp(-x)):
from math import*
def f(x):
y=x-3*(1-exp(-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 ("Root of this given function does not exist between the entered limits.")
a=input("Enter the new lower limit:")
b=input("Enter the 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.00000000001:
break
if f(a)*f(c)<0:
b=c
else:
a=c
s=s+1
print("The root of the given function is=",c,"\nRequired No. of steps:",s)
print("The value of the function at the point of root is=",f(c))
from math import*
def f(x):
y=x-3*(1-exp(-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 ("Root of this given function does not exist between the entered limits.")
a=input("Enter the new lower limit:")
b=input("Enter the 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.00000000001:
break
if f(a)*f(c)<0:
b=c
else:
a=c
s=s+1
print("The root of the given function is=",c,"\nRequired No. of steps:",s)
print("The value of the function at the point of root is=",f(c))
Comments
Post a Comment