Click here to Skip to main content
15,867,895 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
A well-known root-finding algorithm is the secant method. Let f : [a,b] → R. Given two initial guesses x0 and x1, the algorithm defines the sequence of approximations (xn)n∈N0 as
xn :=xn−1−f(xn−1) xn−2−xn−1 for n≥2, f(xn−2) − f(xn−1)
i.e.,the approximationxn is the root of the line that connects the points(xn−2,f(xn−2))and(xn−1,f(xn−1)). Write a function double secant(double (*f)(double), double x0, double x1, double tau),which performs the above iteration until either |f(xn) − f(xn−1)| ≤ τ or

|f(xn)| ≤ τ and |xn − xn−1| ≤ (τ for |xn| ≤ τ   
                              (τ|xn| else.
In the first case, print a warning to inform the user that the result is presumably wrong. The function returns xn as an approximation of a zero of f. Use assert to check that τ > 0. The function requires as input a suitable implementation double f(double x) of the object function f. Moreover, write a main program that reads x0, x1, and τ from the keyboard, calls the function, and prints to the screen the approximate zero xn and the function value f(xn).


What I have tried:

Please help me I don't know how to do this
Posted
Updated 1-Dec-22 5:13am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900