Question: Newton's method is fast, but prone to problems like division by zero. We examine how Newton's method fails: For this, solve f(x) = tanh(x) =

 Newton's method is fast, but prone to problems like division by

Newton's method is fast, but prone to problems like division by zero. We examine how Newton's method fails: For this, solve f(x) = tanh(x) = 0 (hyperbolic Tan) (i) Start with an initial guess Xo 1.08. Plot the tangent (and the function at each iteration of Newton's method. (ii) Repeat with an initial guess xo = 1.09. d(tanh()) Note: 1 tanh(c). dr For this part, write a function to plot the curve and the tangent (like the one shown below), that you can call from your program, After each call to plot_line, you will need a command input ("Hit Enter to Continue") for the program to move to the next iteration. def plot_line (f, xn, fxn, slope): # Plot both f(x) and the tangent xf = linspace(-2,2,100) yf f(xf) xt = linspace(xn-2, xn+2,10) yt = slope*xt + (fxn slope*xn) # Straight line: ax + b plt.figure() plt.plot(xt, yt, 'r-', xf, yf, 'b-') plt.grid('on') plt.xlabel('x') plt.ylabel('f(x)') plt.show() Newton's Method: Set max number of iterations (around 40). Compute fo = f(x0) Compute f'(xo), check that it is non-zero (if f'(xx) at any stage is zero, print an error message and return None. This will terminate the execution of the function. While I fol > tolerance and max iterations not exceeded, f(x0) Calculate X1 = - f' (20) Set Xo = I1, fo = f(xo) increase iteration count. when loop terminates, report x1 as the approximation and the number of iteratio Newton's method is fast, but prone to problems like division by zero. We examine how Newton's method fails: For this, solve f(x) = tanh(x) = 0 (hyperbolic Tan) (i) Start with an initial guess Xo 1.08. Plot the tangent (and the function at each iteration of Newton's method. (ii) Repeat with an initial guess xo = 1.09. d(tanh()) Note: 1 tanh(c). dr For this part, write a function to plot the curve and the tangent (like the one shown below), that you can call from your program, After each call to plot_line, you will need a command input ("Hit Enter to Continue") for the program to move to the next iteration. def plot_line (f, xn, fxn, slope): # Plot both f(x) and the tangent xf = linspace(-2,2,100) yf f(xf) xt = linspace(xn-2, xn+2,10) yt = slope*xt + (fxn slope*xn) # Straight line: ax + b plt.figure() plt.plot(xt, yt, 'r-', xf, yf, 'b-') plt.grid('on') plt.xlabel('x') plt.ylabel('f(x)') plt.show() Newton's Method: Set max number of iterations (around 40). Compute fo = f(x0) Compute f'(xo), check that it is non-zero (if f'(xx) at any stage is zero, print an error message and return None. This will terminate the execution of the function. While I fol > tolerance and max iterations not exceeded, f(x0) Calculate X1 = - f' (20) Set Xo = I1, fo = f(xo) increase iteration count. when loop terminates, report x1 as the approximation and the number of iteratio

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!