To solve the problem by using iterative algorithm, we need to do the following three aspects: first, to determine the iterative variables in the problem that can be solved by the iterative algorithm, we can determine at least one can be directly or indirectly continuously by the old value of the new value of the variable, the variable is an iterative variable. Second, establish an iterative relationship, the so-called iterative relationship, which refers to the formula (or relationship) that introduces its next value from the previous value of the variable. The establishment of iterative relationships is the key to solving iterative problems, which can usually be accomplished by means of recursive or backward-pushing. Third, the iterative process control when to end the iterative process? This is an issue that must be considered in writing an iterative procedure. The iterative process cannot be performed indefinitely. The control of an iterative process can usually be divided into two situations: one is that the desired number of iterations is a definite value that can be calculated, and the other is that the number of iterations required cannot be determined. In the former case, a fixed number of loops can be constructed to control the iterative process, and in the latter case, further analysis is needed to conclude the conditions that can be used to end the iterative process.Next, I present a typical case of an iterative algorithm----Newton-Raphson (Kristinn) method
Newton-Raphson (Kristinn) method, also known as Newton's iterative method, called Newton Tangent method: first arbitrarily set a real root close to the value x0 as the first approximation of the root, from the x0 to find F (x0), Over (X0,f (x0)) point to Do f (x) tangent, intersection x axis in X1, Take it as the second approximate root, and then by the X1 to find F (x1), Over (X1,f (x1)) point do f (x) tangent, cross x axis in X2, ... So continue until the real root x* is close enough (like |x-x0|<1e-6).
and F ' (x0) =f (x0)/(x1-x0)
So x1= x0-f (x0)/F ' (x0).
Let's take a look at a graph found online:
Next, let's look at an example:
We are still directly on the code:
Example: Using Newton's Iterative method to find the following equation at a value equal to 2.0 near the root: 2x3-4x2+3x-6=0 .
#include <stdio.h> #include <math.h> int main (void) {float x,x0,f,f1; x = 2.0;do{ x0=x; f=2*x0*x0*x0-4*x0*x0+3*x0-6; f1=6*x0*x0-8*x0+3; X=X0-F/F1; function Fabs: The absolute value of the floating-point number x //Description: Calculates the |x|, returns x if X is not negative, otherwise returns the-X }while (fabs (x-x0) >=1e-5); printf ("%f\n", X); return 0; }
Execution Result:
When x=1.5, the equation is 2x3-4x2+3x-6=0. The nearby root is 2.000000.
C Language Implementation Newton iterative method solution equation