huangblue / c

0 stars 0 forks source link

Newton-Raphson Iteration Technique #22

Open huangblue opened 7 years ago

huangblue commented 7 years ago

牛顿迭代法

The Newton-Raphson method can be easily described as follows.You begin by selecting a “guess” at the square root of the number.The closer that this guess is to the actual square root, the fewer the number of calculations that have to be performed to arrive at the square root. For the sake of argument, however, assume that you are not very good at guessing and, therefore, always make an initial guess of 1. The number whose square root you want to obtain is divided by the initial guess and is then added to the value of guess.This intermediate result is then divided by 2.The result of this division becomes the new guess for another go-around with the formula. That is, the number whose square root you are calculating is divided by this new guess, added into this new guess, and then divided by 2.This result then becomes the new guess and another iteration is performed. Because you don’t want to continue this iterative process forever, you need some way of knowing when to stop. Because the successive guesses that are derived by repeated evaluation of the formula get closer and closer to the true value of the square root, you can set a limit that you can use for deciding when to terminate the process.The difference between the square of the guess and the number itself can then be compared against this limit—usually called epsilon (ε). If the difference is less than ε, the desired accuracy for the square root has been obtained and the iterative process can be terminated.

huangblue commented 7 years ago

Newton-Raphson Method to Compute the Square Root of x Step 1: Set the value of guess to 1. Step 2: If |guess2 - x| < ε, proceed to step 4. Step 3: Set the value of guess to (x / guess + guess) / 2 and return to step 2. Step 4: The guess is the approximation of the square root.