#Program to find roots by using Newton Raphson for f(x)=x-3(1-exp(-x))
from math import*
def f(x):
y=x-3*(1-exp(-x))
return y
def f1(x):
y=1-3*exp(-x)
return y
x=input("Enter the initial guess value,x0=")
x=float(x)
s=0
while abs(f(x))>.000001 and s<50:
h= f(x)/float(f1(x))
x=x-h
s=s+1
print("The value of the root for the function is:",x,"\nRequired No. of iteration:",s)
from math import*
def f(x):
y=x-3*(1-exp(-x))
return y
def f1(x):
y=1-3*exp(-x)
return y
x=input("Enter the initial guess value,x0=")
x=float(x)
s=0
while abs(f(x))>.000001 and s<50:
h= f(x)/float(f1(x))
x=x-h
s=s+1
print("The value of the root for the function is:",x,"\nRequired No. of iteration:",s)
Comments
Post a Comment