Obtain the root of the equation and the root of the string truncation equation by means of the string truncation method.
THE SECANT METHOD
In numerical analysis, the secant method is a root-finding algorithm that uses a succession of roots of secant lines to better approximate a root of a function f. the secant method can be thought of as a finite difference approximation of Newton's method. however, the method was developed independently of Newton's method, and predated the latter by over 3,000 years.
1/* 2 * ========================================== ========================================================== =========== 3*4 * Filename: secant_method.cc 5*6 * Description: secant method 7*8 * Version: 1.0 9 * Created: July 16, 2015 minutes 26 seconds 10 * Revision: none11 * Compiler: g ++ 12*13 * Author: your name (), 14 * Organization: 15*16 * ============================================ ========================================================== ========== 17 */18 # include <iostream> 19 # include <cmath> 20 using namespace std; 21 22 double f (double x) // function formula 23 {24 return x * x-3 * x-1; 25} 26 27 double point (double a, double B) // calculates the intersection of the string and the X axis 28 {29 return (a * f (B)-B * f ()) /(f (B)-f (a); 30} 31 32 double root (double a, double B) // obtain the equation in [, b] root 33 {34 double x, y, y1; 35 y1 = f (a); 36 do {37 x = point (a, B ); // calculates the intersection x coordinate 38 y = f (x); // calculates y39 if (y * y1> 0) 40 y1 = y, a = x; 41 else42 B = x; 43} while (fabs (y)> = 0.000001); // calculate precision 44 return x; 45} 46 47 int main () 48 {49 double a, B; 50 cin> a> B; 51 cout <"root =" <root (a, B) <endl; 52 return 0; 53}