Rename the function newton_raphson () provided in the code snippet below to secant () and modify it to match the iteration formula of the secant method. Recall that the secant method needs two initial points, which we will pass as the arguments x and x1. The function's signature should be: int secant (double xxi, double x0, double x1, int Nmax, double TOL), where Nmax is the maximum allowed number of iterations and TOL is the tolerance for locating the root. Hint: You will also need to define a second internal variable xp and initialise its value to x1. In each iteration, xp will be updated to the old value of x, and x will be updated to the new point. As with newton_raphson (), the variable xi is passed by reference to secant (), expecting it to fill in the value of the root. This part can be left untouched. Again, the function should return 0 if it finishes successfully and -1 if the maximum number of iterations is exceeded. The stopping condition can also remain the same and there is no need to implement further sanity checks. Do not add any other print statements. Answer: (penalty regime: 10, 20, ... %) Reset answer 1 int newton_raphson (double *xi, double x0, int Nmax, double TOL) { /* Initialize Algorithm */ double x, fx, fpx, dx; int i; X = xa; fx = f(x0); fpx = fp(x0); dx = -fx/fpx; /Run Iteration Loop */ 10 11 12 13 14 i=0; 16 17. 18 19 20 21 12345678901234561 PENELONA222222222222223 while (!((fabs(dx) Nmax))) { dx = -fx/fpx; x += dx; fx = f(x); fpx = fp(x); i++; *xi Xi 24 25 } 26 27 28 29 30 31 33} if (i>Nmax) return -1; else printf("Finished after %d iterations.\n", i); return 0;

Advanced Engineering Mathematics
10th Edition
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Erwin Kreyszig
Chapter2: Second-order Linear Odes
Section: Chapter Questions
Problem 1RQ
icon
Related questions
Question

Using c++

Rename the function newton_raphson () provided in the code snippet below to secant () and modify it to match the iteration formula of the secant method. Recall that the
secant method needs two initial points, which we will pass as the arguments x and x1. The function's signature should be: int secant (double xxi, double x0, double
x1, int Nmax, double TOL), where Nmax is the maximum allowed number of iterations and TOL is the tolerance for locating the root. Hint: You will also need to define a
second internal variable xp and initialise its value to x1. In each iteration, xp will be updated to the old value of x, and x will be updated to the new point.
As with newton_raphson (), the variable xi is passed by reference to secant (), expecting it to fill in the value of the root. This part can be left untouched. Again, the function
should return 0 if it finishes successfully and -1 if the maximum number of iterations is exceeded. The stopping condition can also remain the same and there is no need to
implement further sanity checks. Do not add any other print statements.
Answer: (penalty regime: 10, 20, ... %)
Reset answer
1 int newton_raphson (double *xi, double x0, int Nmax, double TOL) {
/* Initialize Algorithm */
double x, fx, fpx, dx;
int i;
X = xa;
fx = f(x0);
fpx
=
fp(x0);
dx = -fx/fpx;
/Run Iteration Loop */
10
11
12
13
14
i=0;
16
17.
18
19
20
21
12345678901234561
PENELONA222222222222223
while (!((fabs(dx) <TOL) || (i>Nmax))) {
dx = -fx/fpx;
x += dx;
fx = f(x);
fpx = fp(x);
i++;
*xi Xi
24
25
}
26
27
28
29
30
31
33}
if (i>Nmax) return -1;
else printf("Finished after %d iterations.\n", i);
return 0;
Transcribed Image Text:Rename the function newton_raphson () provided in the code snippet below to secant () and modify it to match the iteration formula of the secant method. Recall that the secant method needs two initial points, which we will pass as the arguments x and x1. The function's signature should be: int secant (double xxi, double x0, double x1, int Nmax, double TOL), where Nmax is the maximum allowed number of iterations and TOL is the tolerance for locating the root. Hint: You will also need to define a second internal variable xp and initialise its value to x1. In each iteration, xp will be updated to the old value of x, and x will be updated to the new point. As with newton_raphson (), the variable xi is passed by reference to secant (), expecting it to fill in the value of the root. This part can be left untouched. Again, the function should return 0 if it finishes successfully and -1 if the maximum number of iterations is exceeded. The stopping condition can also remain the same and there is no need to implement further sanity checks. Do not add any other print statements. Answer: (penalty regime: 10, 20, ... %) Reset answer 1 int newton_raphson (double *xi, double x0, int Nmax, double TOL) { /* Initialize Algorithm */ double x, fx, fpx, dx; int i; X = xa; fx = f(x0); fpx = fp(x0); dx = -fx/fpx; /Run Iteration Loop */ 10 11 12 13 14 i=0; 16 17. 18 19 20 21 12345678901234561 PENELONA222222222222223 while (!((fabs(dx) <TOL) || (i>Nmax))) { dx = -fx/fpx; x += dx; fx = f(x); fpx = fp(x); i++; *xi Xi 24 25 } 26 27 28 29 30 31 33} if (i>Nmax) return -1; else printf("Finished after %d iterations.\n", i); return 0;
Expert Solution
steps

Step by step

Solved in 1 steps with 1 images

Blurred answer
Recommended textbooks for you
Advanced Engineering Mathematics
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
Numerical Methods for Engineers
Numerical Methods for Engineers
Advanced Math
ISBN:
9780073397924
Author:
Steven C. Chapra Dr., Raymond P. Canale
Publisher:
McGraw-Hill Education
Introductory Mathematics for Engineering Applicat…
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
Mathematics For Machine Technology
Mathematics For Machine Technology
Advanced Math
ISBN:
9781337798310
Author:
Peterson, John.
Publisher:
Cengage Learning,
Basic Technical Mathematics
Basic Technical Mathematics
Advanced Math
ISBN:
9780134437705
Author:
Washington
Publisher:
PEARSON
Topology
Topology
Advanced Math
ISBN:
9780134689517
Author:
Munkres, James R.
Publisher:
Pearson,