Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started