Python question: def secant_method(f,x0,x1,tol,kmax): # YOUR CODE HERE raise NotImplementedError()

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Python question: def secant_method(f,x0,x1,tol,kmax): # YOUR CODE HERE raise NotImplementedError()

Post by answerhappygod »

Python question:
def secant_method(f,x0,x1,tol,kmax):
# YOUR CODE HERE
raise NotImplementedError()
Python Question Def Secant Method F X0 X1 Tol Kmax Your Code Here Raise Notimplementederror 1
Python Question Def Secant Method F X0 X1 Tol Kmax Your Code Here Raise Notimplementederror 1 (107.12 KiB) Viewed 47 times
Python Question Def Secant Method F X0 X1 Tol Kmax Your Code Here Raise Notimplementederror 2
Python Question Def Secant Method F X0 X1 Tol Kmax Your Code Here Raise Notimplementederror 2 (90.7 KiB) Viewed 47 times
Introduction The Secant Method can be used to find a root, Xx, of a function f(x) so that f(xx) = 0. This method is an adaptation of Newton's method, where the derivative is estimated using the approximation: f'(xk) – f(xk) – f(xk-1). Xk — Xk-1 In the Secant Method a sequence of successive estimates for Xx , labelled { xk}k>1, are calculated using the formula 1 Xk – Xk-1 Xk+1 = xk f(xk). f(xk) – f(xk-1) Geometrically Xk+1 is obtained from xk and Xx–1 by intersecting the straight line through (xx, f(xx)) and (xk+1, f(xx+1)) with the x-axis. Since each calculation of the new estimate, Xk+1, requires the values of the previous two estimates, xk and Xk-1, we must specify xo and xį initially, choosing values that are close to the root we seek. Ideally, we should choose xo and xı in a similar way to the initial endpoints of an interval for the bisection method, such that f(x) = 0 precisely once in the interval (x0, xi), though this is not necessary for the secant method to work. =
(a) [30 Marks] : Write a function, 'secant_method', which takes as input a function f, two real numbers to and xi, a positive real number tol and a positive integer kmax. This function should implement the Secant Method to find a root of a function f using the two starting points xo and X1. Successive estimates should be calculated until the relative error ek is less than tol or k > kmax: Recall that Xk – xk-1 ek Xk . • If no root is found an ArithmeticError should be raised. If tol < 0 then a ValueError sould be raised. If k max < 0 then a ValueError should be raised. If xo == xj then a ValueError should be raised. • Otherwise the function should return a tuple (xn, en, N) consisting of the final approximation, xn, the estimated relative error, en and the index of the approximation, N.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply