Skip to main content

Program to find root using Regula Falsi method for f(x)=x-3(1-exp(-x))

#Program to find root using Regula Falsi method for f(x)=x-3(1-exp(-x))
from math import*
def f(x):
 y=x-3*(1-exp(-x))
 return y
a=input("Enter the upper limit:")
b=input("Enter the lower limit:")
a=float(a)
b=float(b)
while f(a)*f(b)>0:
 print("The root for the given function does not exist between the entered limits.")
 a=input("Enter the new upper limit:")
 b=input("Enter the new lower limit:")
 a=float(a)
 b=float(b)
s=0
while (f(a)*f(b))<0:
 c=(a*f(b)-b*f(a))/(f(b)-f(a))
 if abs(f(c))<0.00000000001 or (a-b)<.0000001 :
  break
 if f(a)*f(c)<0:
  b=c
 else:
  a=c
 s=s+1
print("The solution of the entered function is =",c,"\nRequired No. of steps:",s)
print("The value of the function at the point of solution is=",f(c))

Comments