Common algorithm design method (I)-Iterative Method

Source: Internet
Author: User
Iteration Method is a common algorithm design method used to obtain the approximate root of equations or equations. Set the equation to f (x) = 0, use a mathematical method to export the equivalent form X = g (x), and then follow these steps:
(1) Select the approximate root of an equation and assign it to variable x0;
(2) Save the value of x0 to the variable X1, calculate g (X1), and save the result to the variable x0;
(3) when the absolute value of the difference between x0 and X1 is smaller than the specified precision requirement, repeat the calculation in step (2.
If the equation has roots and the approximate root sequence obtained by the above method converges, The x0 obtained by the above method is considered as the root of the equation. The above algorithm is represented in the form of a C program:
[Algorithm] iterative method is used to find the root of the equation.
{X0 = initial approximate root;
Do {
X1 = x0;
X0 = g (X1);/* calculate a new approximate root based on a specific equation */
} While (FABS (x0-x1)> epsilon );
Printf ("the approximate root of the equation is % F/N", X0 );
}
Iterative algorithms are also often used to find the root of the equations.
X = (x0, X1 ,..., Xn-1)
Set the equations:
Xi = GI (x) (I = 0, 1 ,..., N-1)
The Iterative Algorithm for Finding the root of the equations can be described as follows:
[Algorithm] iterative method is used to obtain the root of the equations.
{For (I = 0; I <n; I ++)
X = Initial approximate root;
Do {
For (I = 0; I <n; I ++)
Y= X;
For (I = 0; I <n; I ++)
X= GI (X );
For (delta = 0.0, I = 0; I <n; I ++)
If (FABS (Y-X)> Delta) Delta = FABS (Y-X);
} While (delta> epsilon );
For (I = 0; I <n; I ++)
Printf ("the approximate root of variable X [% d] is % F", I, X);
Printf ("/N ");
}
Pay attention to the following two possible situations when using iterative methods to root out:
(1) If the equation has no solution, the approximate root sequence obtained by the algorithm will not converge, and the iteration process will become an endless loop. Therefore, before using the iterative algorithm, we should first check whether the equation has a solution, limit the number of iterations in the program;
(2) Although the equation has solutions, improper selection of iteration formulas or unreasonable selection of the initial approximate root of iteration may also lead to iteration failure.

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.