Newton iterative method beg square root of a number

Background: Newton iterative method ( Newton's Method, ), also known as the Newton - Raphson method (Newton-Raphson
Method,)
, which is Newton's method for proposed in the 17th century in the field of real numbers and complex field approximation to solve the equation. There is no majority equation root formula, and therefore seek accurate root very difficult, if not impossible, to find so approximate roots of the equation is especially important. The method of using the function f (x) in front of several Taylor series to find the equation f (x)
= 0 of the root. Newton iterative method is an important method of Equation Root, which is the biggest advantage in the equation = f (x)
having a single quadratic convergence near 0, and the process may also be used to find the Roots of equations, complex roots, then linear convergence, but it may become superlinear convergence by some means. In addition, this method is widely used in computer programming.
Newton iterative formula

  Let r is f (x) = root 0, select x0 as r initial approximation, through the point (x0, F (x0)) to make the curve y = f (x) tangent L, L of the equation y = f (x0 ) + f '(x0) ( x-x0), the intersection of the x-axis is obtained L abscissa x1 = x0-f (x0) / f' (x0), x1 is called a first approximation of r. Through the point (x1, f (x1)) to make the curve y = f (x) is the tangent, the abscissa and determining the x2-axis intersection of the tangent and x is = x1-f (x1) / f '(x1), x2 is called secondary approximation of r. Repeat the above procedure to give an approximation of the sequence r, where x (n + 1) = x (n) -f (x (n)) / f '(x (n)), called r n + 1 times of approximation, the type known as Newton iterative formula .

 

  Nonlinear Equations f (x) = 0 The Newton's method is an approximate method to linearize nonlinear equations. The f (x) in the vicinity of point x0 expanded into Taylor series f (x) = f (x0 ) + (x-x0) f '(x0) + (x-x0) ^ 2 * f' '(x0) / 2! + ...
whichever linear part, as a nonlinear equation f (x) = 0 approximate equation, i.e., Taylor expansion of the first two, there are f (x0) + f '( x0) (x-x0) = 0
provided f '(x0) ≠ 0 it is a solution x1 = x0-f (x0) / f' (x0) Thus, to obtain a sequence of iterative Newton's method: x (n + 1) = x (n) -f ( x (n)) / f ' (x (n)).

 

Newton iterative method schematic

  Military offensive attack often used alternately cover the way, if the position represented by A, B at two points on the number line, the predetermined number is greater than the number behind the front, it is A> B, B> A alternately. But now assume that the military has a coward, but at the same time we are taking care of him, so that each charge are behind him, in front of people whenever occupy a new position, put the position to him, then others again forward conquer new location. That is always in front of the B of A, A forward, to keep up with B, A to B to their position (ie the implementation of B
= A operation), then A go forward to conquer new location, talk to the B ...... until all the occupied positions, forward end. Like this one after the two numbers called stepwise iterative method of approximation to a location method.

  Iterative method, also known as flounder law is an ongoing process of recursive new value with the old value of the variable, with the iteration wears corresponds to the direct method (or referred to as a solution), a one-time problem solving. Iterative algorithm to solve the problem with a computer-based method. It uses the computing speed, suitable for repetitive operation characteristics, so that a set of instructions for the computer (or a certain step) is repeatedly executed, each time the set of instructions (or these steps) performed, all the variables from the original value it launched a new value.

 

  Using an iterative algorithm to solve the problem, we need to do the following three aspects:

  First, determine the iteration variable. The problem can be solved by an iterative algorithm, at least there is a direct or indirect ever launched by the old value of the delivery of the new value of the variable, the variable is the iteration variable.

 

      Second, the establishment of an iterative relationship. The so-called iterative relationship, refers to how the introduction of a formula under which a value (or relationship) from the previous value of the variable. The establishment of an iterative relationship is the key to solving the problem of iteration, you can usually use recursion or push down to complete.

  Third, the iterative process is controlled. In the end what the iterative process? This is a problem to write iterative programs must be considered. Can not let the iterative process endlessly repeat the down. Iterative process can generally be divided into two cases: one is the number of iterations required is determined value, can be calculated; the other is the number of iterations required could not be determined. In the former case, it is possible to build a fixed number of cycles to achieve control of the iterative process; the latter case, the need for further analysis of the condition of the end of the iterative process. (Excerpt from Baidu Encyclopedia: http://baike.baidu.com/view/643093.htm )

 

Reference code is as follows:

/**

Considering only non-negative square root of the real number,

If you want to fully consider, and then modify it yourself

*/

#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    double a ;
    cin>>a ;
    double x = 1 ;
    while(x*x - a > 0.0000001 || x*x - a < -0.0000001)
    {
       x = (x + a/x)/2 ;
    }
    cout<< fabs(x) ;
    return 0;
}

Reproduced in: https: //www.cnblogs.com/ronaldHU/archive/2012/10/07/2714344.html

Guess you like

Origin blog.csdn.net/weixin_33805743/article/details/94272126