The secant METHOD
In numerical analysis, the secant method was a root-finding algorithm that uses a succession of roots of secant lines to be tter 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.cc5 *6 * Description:secant Method7 *8 * version:1.09 * created:2015 July 16 13:53 26 secondsTen * Revision:none One * compiler:g++ A * - * Author:your NAME (), - * Organization: the * - * ===================================================================================== - */ -#include <iostream> +#include <cmath> - using namespacestd; + A DoubleFDoubleX//The function formula of the required solution at { - returnX*x*x-3*x-1; - } - - DoublePointDoubleADoubleb//solving the intersection of the chord and the x-axis - { in return(A*f (b)-b*f (a))/(f (b)-f (a)); - } to + DoubleRootDoubleADoubleb//to find the root of the equation in the [a, b] interval by using the chord-intercept method - { the Doublex, y, y1; *Y1 =f (a); $ Do {Panax Notoginsengx = Point (A, b);//finding the x-coordinate of intersection -y = f (x);//Ask y the if(Y*y1 >0) +Y1 = y, a =x; A Else theb =x; +} while(Fabs (y) >=0.000001);//Computational Precision - returnx; $ } $ - intMain () - { the DoubleA, B; -Cin>>a>>b;Wuyicout<<"root ="<<root (A, b) <<Endl; the return 0; -}
Finding the root of equation by chord-truncation method