Finding the root of equation by chord-truncation method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.