Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to solve it using Python code 5. (5 points) Write a function called newton w

ID: 3726351 • Letter: H

Question

How to solve it using Python code

5. (5 points) Write a function called newton which takes input parameters f, To, h (with default value 0.001), tolerance (with default value 0.001) and max_iter (with default value 100). The function implements Newton's method to approximate a solution of f(z)-0. In other words, compute the values of the recursive sequence starting at To and defined by Use the central difference formula with step size h to approximate the derivative f(). The desired result is that the method converges to an approximate root of f(r) however there are (a) The sequence reaches the desired tolerance f()tolerance and newton returns the (b) The number of iterations exceeds the maximum number of iterations max_iter, the (c) A zero derivative is computed f'(Fn) = 0, the function prints the statement "Zero several possibilities: value n function prints the statement "Maximum iterations exceeded." and returns None derivative." and returns None

Explanation / Answer

def newton(f,x0,h=.001,tolerance=.001,max_iter=100): x = x0 i = 0 while (abs(f(x)) > tolerance): fdash=(f(x+h)-f(x-h))/(2*h) if fdash==0: print('Zero derivative') return None x = x - f(x) / fdash i = i + 1 if i >max_iter: print('Maximum iterations exceeded') return None return x

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote