Python question
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. =
c) [30 Marks] Consider the rational function f(x) = x3 – x2 + 2x + 1 3x2 + 2 Use the function from b) with initial approximations xo = -2 and xı = 1 to compute a list of approximations, Xo, X1, ... , xn to the unique real zero of f (which lies between xo and xi). Illustrate the Secant Method by plotting • a) The curve of f. • b) The x-axis. . c) The five points zi = (x;, f(x;)) for 0 <i< 4 on the curve, d) The four straight lines (secants) between zo and 21, 21 and 22, z2 and zz, and 23 and 24. . The plot should have the following properties: • size (20,10), • be limited in both x and y-directions in such a way that the relevant parts of the graphs and intersections are clearly visible. • have title "Secant Method" . have x-label "X" have y-label "y" Insert the plotting code in the cell below and execute the plot. Note: • The convergence for these particular starting values is slow in the beginning so the first few points will not clearly illustrate the actual convergence. • If you couldn't complete the function secant_method_list in part (a) you can use the list of xk values below: xk_list = [(-2,-0.8823529411764706), (1, 0.6), (-0.2142857142857142, 0.43565270935960626), (-3. 43312101910829, -1. 2071053485428982), (-1.067907655010679, -0.6282446220268515), (1. 4990873195554006, 0.5125366680719312), (0.34577330341514423, 1. 0913866439007789), (2.52 02771748832404, 0.5944232424737134), (5. 121224525005979, 1. 126731007706626), (-0.38417708699829944, 0.017198731189609955), (-0.469515 6791417744, -0.13974998009946765), (-0.3935286483734805, -0.0017696204621476153), (-0.39255410239564087, 0.00018620814380429187), (- 0.3926468857801528, -2. 0908434934148662e-07), (-0.3926467817149128, -2. 465352397328274e-11), (-0.39264678170264083, 0.0)]
Python question
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am