Overview
Newton Iterative method is a numerical algorithm, which can be used to find 0 points of a function. The idea is to abstract the function into a straight line, step by step with the estimated approximation function of 0 points.
The approximation speed is very efficient, and it is often possible to obtain very accurate results in more than 10-step iterations.
Lemma
Consider a line in the following coordinate system \ (xoy\) :
The value at \ (x=x_0\) is a value of \ (y_0\). So what is the \ (x\) coordinate \ (a\) of the intersection of this line and the \ (x\) axis?
The analytic formula for this line is \ (y=kx+b\), then there is
\[y_0=kx_0+b\]
That
\[b=y_0-kx_0\]
Order \ (y=0\), get the equation
\[kx+y_0-kx_0=0\]
Solution to
\[x=\frac{kx_0-y_0}{k}\]
That
\[x=x_0-\frac{y_0}{k}\]
Newton Iterative Method
We formally began using Newton's iterative method to find the function \ (f (x) \) 0 points.
problem : try \ (\sqrt{2}\) approximate value.
The original proposition is equivalent to the 0 points of the function \ (f (x) =x^2-2\) .
First step: Guess the initial value
First we randomly guess a value. Set it to \ (x=4\) .
Step Two: Iteration
Over \ ((x,f (x)) \) point for \ (f (x) \) tangent, get:
According to the geometric meaning of the derivative, the slope of this line is \ (f ' (x) \), then according to the conclusion we obtained earlier, the function and the \ (x\) coordinates of the intersection of the \ (x\) axis are
\[x ' =x-\frac{f (x)}{f ' (x)}\]
According to the best estimate, if the derivative does not change, the 0 point should be in that position. Then we make \ (x=x '), which is called an iteration.
Back to the example. \ (f (x) =x^2-2\), then \ (f ' (x) =2x\):
\[x ' =x-\frac{f (x)}{f ' (x)}=x-\frac{x^2-2}{2x}=\frac{x}{2}+\frac{1}{x}\]
Each time you replace \ ( \frac{x}{2}+\frac{1}{x}\) with \ (x\), repeat the above process:
As you can see, the exact value of the \ (20\) bit is obtained with just six iterations.
The procedure is as follows:
#include<iostream>#include<cstdio>#include<cmath>using namespace std;const double eps=1e-10;double a,x;double f(double x){return x*x-a;}double df(double x){return 2*x;}int main(){ scanf("%lf",&a); x=1; while(fabs(f(x))>=eps)x-=f(x)/df(x);
Intuitive understanding of Newton iterative method