Question: In the below code of python implementation of Newton Raphson Method, the equation in return variable should be taken as input. It is hard coded
In the below code of python implementation of Newton Raphson Method, the equation in return variable should be taken as input. It is hard coded right now but it should be taken as user input. Kindly update the code.
Code:
#EQ-1
import math
def f(x):
return math.cos(x) - 1.3 * x
def g(x):
return -math.sin(x) - 1.3
def NewtonRaphson(x0,e):
Iteration = 1
CodeCondition = True
while CodeCondition:
x1 = x0 - f(x0)/g(x0)
print('Iteration-%d' % (Iteration)),
print('x1 = %0.6f and f(x1) = %0.6f' % (x1, f(x1)))
x0 = x1
Iteration = Iteration + 1
CodeCondition = abs(f(x1)) > e
print(' Required root is: %0.8f' % x1)
x0 = float(input('Enter Value of x0: '))
e = float(input('Tolerable Error: '))
NewtonRaphson(x0,e)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
