Question: Using the Newton - Raphson iteration find the root of the equation x + x 2 = 7 . With an initial guess of x
Using the NewtonRaphson iteration find the root of the equation xx With an initial guess of x compute the number of iterations required for the error in the root to be below e
This is my code, the root is correct but the number of iterations is off by one it should be but I keep getting :
import math
def fx:
return math.sqrtx x
def dfx:
return math.sqrtx x
def newtonraphsonx tol, fullouptutTrue:
numiter
error tol
while error tol:
x xfx dfx
error absx x
x x
numiter
return x numiter
x
tol e
root numiter newtonraphsonx tol, numiter
printNewtonRaphson method root and numiter:", root numiter
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
