#Program to find root by secant method for y=x-tanh(2x):
from math import*
def f(x):
y=x-tanh(2*x)
return y
a=input("Enter the upper limit:")
b=input("Enter the lower limit:")
a=float(a)
b=float(b)
c=(a*f(b)-b*f(a))/(f(b)-f(a))* 1.0
s=0
while abs(f(c))>0 & s<50:
a=b
b=c
c=(a*f(b)-b*f(a))/(f(b)-f(a))
s=s+1
print("The root of the function is=",c,"\nThe No. of required steps:",s)
print("Function's value at the point of root=",f(c))
from math import*
def f(x):
y=x-tanh(2*x)
return y
a=input("Enter the upper limit:")
b=input("Enter the lower limit:")
a=float(a)
b=float(b)
c=(a*f(b)-b*f(a))/(f(b)-f(a))* 1.0
s=0
while abs(f(c))>0 & s<50:
a=b
b=c
c=(a*f(b)-b*f(a))/(f(b)-f(a))
s=s+1
print("The root of the function is=",c,"\nThe No. of required steps:",s)
print("Function's value at the point of root=",f(c))
Comments
Post a Comment