#Program to find root using secant method for f(x)=x-3(1-exp(-x))
from math import*
def f(x):
y=x-tan(x)
return y
a=input("Enter the 1st value:")
b=input("Enter the 2nd value:")
a=float(a)
b=float(b)
c=(a*f(b)-b*f(a))/(f(b)-f(a))*1.0
s=0
while abs((c-b)/c)>0.00000000001 and s<500:
a=b
b=c
c=(a*f(b)-b*f(a))/(f(b)-f(a))*1.0
s=s+1
print("The root for the given function is =",c,"\nThe No. of steps required:",s)
print("Function's value at point of root=",f(c))
from math import*
def f(x):
y=x-tan(x)
return y
a=input("Enter the 1st value:")
b=input("Enter the 2nd value:")
a=float(a)
b=float(b)
c=(a*f(b)-b*f(a))/(f(b)-f(a))*1.0
s=0
while abs((c-b)/c)>0.00000000001 and s<500:
a=b
b=c
c=(a*f(b)-b*f(a))/(f(b)-f(a))*1.0
s=s+1
print("The root for the given function is =",c,"\nThe No. of steps required:",s)
print("Function's value at point of root=",f(c))
Comments
Post a Comment