Question: Fill in the gaps in the function newton _ root _ finder below so that it returns the approximation xn + 1 for a root
Fill in the gaps in the function newtonrootfinder below so that it returns the approximation xn for a root of the given function f f with derivative f fprime found using Newton's method with initial approximation x using the given tolerance value applied to both the function error and the approximation change, ie iteration stops when both of the following are true:
fxnandxnxn
provided that this happens without exceeding the specified maximum number of iterations maxiterations. If the specified maximum number of iterations is exceeded the function should raise a RuntimeError with the message "Max iterations reached without convergence in newtonrootfinder".
For example, if the function is tested with the code below:
f lambda x: x x
fprime lambda x: x
x
tol e
maxiterations
try:
root newtonrootfinderf fprime, x tol, maxiterations
printfRoot found root:f dps
except RuntimeError as err:
printerr
the test code should print:
Root found dps
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
