Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the following code to obtain a Python function for performing Newton's method for a given function f . Input Arguments Your function should take

Modify the following code to obtain a Python function for performing Newton's method for a given function f.
Input Arguments
Your function should take the following as input:
Functions for evaluating f(x) and its derivative f'(x).
Initial solution x0.
Maximum number of iterations and stopping tolerance.
Output Arguments
Your function should return the following as output:
The finite sequence of solutions {x0,x1,dots,xk}, where xk is the solution when the algorithm is terminated.
The sequence of absolute differences in consecutive iterates {|x1-x0|,|x2-x1|,dots,|xk-xk-1|}.
The number of iterations performed.
The function below gives the general form of Newton's Method but is missing code for executing several steps, e.g., calculating xk from xk-1, updating the residuals |xk-xk-1|. You will need to modify the given code to include these steps.
[]: def Newton(f,df,x0, nmax, tol):
""n"
Performs Newton-Raphson Method to calculate a root of function f.
f : function for evaluating f
df: function for evaluating f'
x0 : initial iterate.
nmax: maximum number of iterates to perform.
tol: stopping tolerance
return sequence of approximate roots and number of iterations performed.
""n
# Import numpy.
import numpy as np
# Initialization.
iter =0 # Number of iterations is 0.
fx= tol +1 # Initialize function value to be greater than tol.
errs = np.ones (nmax+1) # Initial vector of errors.
# Update iterate until a root is found or max # of iterations are performed. while (iter nmax and errs[iter]> tol):
# Calculate function value and derivative value.
iter
image text in transcribed

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

Step: 3

blur-text-image

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

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions