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 *xi, 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 x, int Nmax, double TOL) { 10 11 12 13 14 15 16 17-> /* Initialize Algorithm */ double x, fx, fpx, dx; int i; X = XÔ; fx = f(x0); fp(x0); fpx = dx = -fx/fpx; /* Run Iteration Loop */ i=0; while (!((fabs(dx) < TOL) || (i>Nmax))) { 234567890123+ 25 } 26 27 28 29 30 31 33 } *=22=222222222222222223 18 19 20 21 24 dx = -fx/fpx; x += dx; fx = f(x); fpx = fp(x); i++; if (i>Nmax) return -1; else printf("Finished after %d iterations.\n", i); return 0;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

coding in 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 *xi,
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 x, int Nmax, double TOL) {
/* Initialize Algorithm */
double x, fx, fpx, dx;
2
3
4
5
6
int i;
7
8
9
10
11
12
13
14
15
16
x = x®;
fx = f(x0);
fpx =
dx =
fp(x0);
-fx/fpx;
/* Run Iteration Loop */
i=0;
17▼ while (!((fabs(dx) < TOL) || (i>Nmax))) {
18
19
20
24
25
}
26
27
28
29
30
12222222222222223
33}
dx = -fx/fpx;
x += dx;
fx = f(x);
fpx
i++;
=
fp(x);
*xỉ = Xã
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 *xi, 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 x, int Nmax, double TOL) { /* Initialize Algorithm */ double x, fx, fpx, dx; 2 3 4 5 6 int i; 7 8 9 10 11 12 13 14 15 16 x = x®; fx = f(x0); fpx = dx = fp(x0); -fx/fpx; /* Run Iteration Loop */ i=0; 17▼ while (!((fabs(dx) < TOL) || (i>Nmax))) { 18 19 20 24 25 } 26 27 28 29 30 12222222222222223 33} dx = -fx/fpx; x += dx; fx = f(x); fpx i++; = fp(x); *xỉ = Xã if (i>Nmax) return -1; else printf("Finished after %d iterations.\n", i); return 0;
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education