#Program to find root by regula falsi method for function y=x-tanh(2x):
from math import*
def f(x):
y=x-tanh(2*x)
return y
a=input("Enter the value of upper limit:")
b=input("Enter the value of lower limit:")
a=float(a)
b=float(b)
while f(a)*f(b)>0:
print("The roots of the given function does not lie 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 function is=",c, "\nThe required No. of steps:",s)
print ("The value of the function at the point of solution is=",f(c))
from math import*
def f(x):
y=x-tanh(2*x)
return y
a=input("Enter the value of upper limit:")
b=input("Enter the value of lower limit:")
a=float(a)
b=float(b)
while f(a)*f(b)>0:
print("The roots of the given function does not lie 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 function is=",c, "\nThe required No. of steps:",s)
print ("The value of the function at the point of solution is=",f(c))
Comments
Post a Comment