Answered step by step
Verified Expert Solution
Link Copied!

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 newton_root_finder below so that it returns the approximation xn+1 for a root of the given function f = f with derivative f= f_prime found using Newton's method with initial approximation x0, 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:
|f(xn+1)|<and|xn+1xn|<
provided that this happens without exceeding the specified maximum number of iterations max_iterations. If the specified maximum number of iterations is exceeded the function should raise a RuntimeError with the message "Max iterations reached without convergence in newton_root_finder".
For example, if the function is tested with the code below:
f = lambda x: x**3+ x +1
f_prime = lambda x: 3* x**2+1
x0=-1
tol =0.5e-3
max_iterations =20
try:
root = newton_root_finder(f, f_prime, x0, tol, max_iterations)
print(f"Root found {root:.6f}(6 dps)")
except RuntimeError as err:
print(err)
the test code should print:
Root found -0.682328(6 dps)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions