Introduction to Iterations-from Sogou encyclopedia

Source: Internet
Author: User

In Rup, iterations are defined as: iterations include all development activities that produce a product release (stable, executable product version) and all other peripheral elements necessary to use the publication.

1Related conceptual functions

In mathematics, the iterative function is the object of deep study in the broken shape and dynamical system. Iterative functions are repetitive functions that are complex to themselves, and this process is called iteration.

Model

Iterative models are the recommended periodic models for RUP (rationalunifiedprocess, unified software development process, unified software process).

Algorithm

Iterative algorithm is a basic method to solve the problem by computer. It uses the computer speed, suitable for repetitive operation characteristics, so that the computer to a set of instructions (or a certain number of steps) repeated execution, each time the set of instructions (or these steps), the variable from the original value of the introduction of its new value.

2RUP Model Understanding

If you think this explanation is difficult to understand, think of it this way:

We develop a product that, if not too complex, uses a waterfall model, simply by defining the requirements, then building the framework, then writing the code, then testing, and finally releasing a product.

In this way, a few months later, until the last day of release, we can see a product.

This way has obvious shortcomings, if we judge the user's needs is not very accurate-this is a very common problem, a lot of see-you work for a few months or even years, when you bring the product to the customer, the customer will often be surprised, this is what I want?

Method

The way of iteration is different, if this product requires 6 months delivery, I will come up with a product in the first month, of course, this product will be very imperfect, there will be a lot of features have not been added, many bugs, but also unstable, but the customer looked later, will put forward more detailed changes in opinion, so, You know how far away from the customer's needs, I go home, and then spend one months, in the last month of the needs of analysis, framework design, code, testing, and so on the basis of further improvement, but also come up with a more perfect product to the customer to see, let them comment.

In this way, my products in the functional, quality can be gradually approaching the requirements of customers, will not appear I spent a lot of painstaking efforts, until the end of the release only to find that the customer is not what the situation.

Advantage

This method is good, but he also has his own shortcomings, that is the cycle is long, high cost. In dealing with large projects, high-risk projects-such as the Space Shuttle's control system-the cost of the iteration is much lower than the cost of the project's failure, which is clearly advantageous in this way.

If you are to your own unit to develop a small mis, oneself also more clear demand, the duration also spend a month of time, with the iteration on a bit kill chicken with sledgehammer, that or waterfall model more useful, even if is not done, at most again spend one months again, nothing great.

3Introduction to Algorithm Introduction

Some foreign textbooks, such as "C++primer" fourth edition of the Chinese version, will translate iterative into iterations.

In Java, iterative is used only to iterate over a collection, and does not itself provide the ability to dress objects. If you need to create a iterative object, you must have a collection that is iterated. No collection of iterative as if tree without roots, no existence of value. Iterative are repeated meanings, so sometimes iterations also refer to the meaning of cyclic execution, repeated execution.

Iterative algorithm is a basic method to solve the problem by computer. It uses the computer speed, suitable for repetitive operation characteristics, so that the computer to a set of instructions (or a certain number of steps) repeated execution, each time the set of instructions (or these steps), the variable from the original value of the introduction of its new value.

Using an iterative algorithm to solve the problem requires doing the following three things:

Determining variables

In a problem that can be solved with an iterative algorithm, there is at least one variable that, directly or indirectly, is continuously introduced with the new value by the old value, which is the iteration variable.

Establish a relational style

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.

Process Control

When does the iteration process end? This is an issue that must be considered in writing an iterative procedure. You cannot allow iterative processes to repeat 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, the conditions for ending the iterative process need to be further analyzed.

Example 1: A new breed of rabbit is introduced into a breeding farm, which starts the next month of birth, and the newborn rabbit is bred as a newborn rabbit. If all the rabbits don't die, ask the 12th month, how many rabbits are there in the farm?

Analysis: This is a typical recursive problem. We may as well assume the 1th month when the rabbit's number is U1, the 2nd month when the rabbit's number is U2, 3rd months when the rabbit's number is U3, ... According to test instructions, "This rabbit starts with a new rabbit every month from the next month of birth."

The following is a reference fragment:

U1=1,u2=u1+u1x1=2,u3=u2+u2x1=4, ...

According to this rule, the following recursive formula can be summed up:

The following is a reference fragment:

un= (un-1) x2 (n≥2) *①

For UN and un-1, define two iteration variables y and x to convert the above recursive formula to the following iteration relationship:

The following is a reference fragment:

Y=x*2

X=y

By having the computer repeat 11 times for this iterative relationship, you can figure out the number of rabbits in the 12th month. The reference program is as follows:

The following is a reference fragment:

Cls

X=1

Fori=2to12

Y=x*2

X=y

Nexti

Printy

End

Example 2: Amoeba breeds in a simple, split way, which takes 3 minutes each time it is split. A number of amoeba were placed in a container filled with nutrients, and after 45 minutes the container was filled with amoeba. A known container can be up to 220 amoeba. How many amoeba were placed in the container at the beginning? Please compile the procedure to calculate.

Analysis: According to test instructions, amoeba splits every 3 minutes, then from the beginning of the amoeba into the container, to 45 minutes after filling the container, need to split 45/3=15 times. The "container can be up to 220 amoeba", that is, the amoeba split 15 times after the number is 220. The topic requires us to calculate the number of amoeba before splitting, so we can use a backward method, from 220 after the 15th Division, to roll out the number of the 15th Division (after the 14th Division), and then further reverse the 13th Division after the 12th Division 、...... Number before the 1th division.

The number before the 1th division is x0, the number after the 1th division is X1, and the number after the 2nd division is X2 、...... The number after the 15th Division is x15, then there is

The following is a reference fragment:

X14=X15/2, X13=X14/2 、...... xn-1=xn/2 (n≥1)

Because the number x15 after the 15th split is known, if you define an iteration variable of x, you can convert the above backward formula to the following iteration formula:

X=X/2 (The initial value of x is the number after the 15th Division 220)

With this iterative formula repeated 15 times, you can pour out the number of amoeba before the 1th split. Because the number of iterations required is a definite value, we can use a fixed number of loops to achieve control over the iterative process. The reference program is as follows:

The following is a reference fragment:

Cls

X=2^20

Fori=1to15

X=x/2

Nexti

Printx

End

Example 3: Verifying the valley angle conjecture. The Japanese mathematician, JINGFE, found a strange phenomenon when studying the natural numbers: for any natural number n, if n is even, divide it by 2, and if n is odd, multiply it by 3 and then add 1. The natural number 1 can always be obtained after the finite operation. The discovery of the valley JINGFE is called the "valley conjecture".

Requirements: Write a program, by the keyboard input a natural number n, the n after a finite number of operations, and eventually become the natural 1 of the whole process of printing out.

Analysis: Define the iteration variable to n, according to the content of Gucher conjecture, can get the iterative relation of two cases: when n is even, N=N/2; when n is odd, n=n*3+1. To describe it in QBasic language is:

The following is a reference fragment:

IFN to even then

N=n/2

Else

N=n*3+1

endif

This is the iterative process that requires repeated computer execution. This iterative process needs to be repeated several times to make the iteration variable n eventually become the natural number 1, which we cannot calculate. Therefore, it is also necessary to further determine the conditions used to end the iterative process. Careful analysis of the requirements of the topic, it is not difficult to see, for any given a natural number N, as long as the finite number of operations, the natural numbers can be obtained 1, has completed the verification work. Therefore, the conditions used to end the iterative process can be defined as: N=1. The reference program is as follows:

The following is a reference fragment:

Cls

Input "pleaseinputn="; n

Dountiln=1

Ifnmod2=0then

REM If n is an even number, the iteration formula is called N=N/2

N=n/2

print "-"; n;

Else

N=n*3+1

print "-"; n;

endif

Loop

End

4function Introduction

Iterative method is a common algorithm design method for solving the approximate root of equations or equations. Set the equation to f (x) = 0, use a mathematical method to derive the equivalent form x=g (x), and then follow these steps:

⑴ Select an approximate root of an equation and assign it to a variable x0;

⑵ saves the value of x0 in the variable x1, then calculates G (x1) and stores the result in the variable x0;

⑶ the calculation of the step ⑵ is repeated when the absolute value of the difference between the x0 and the X1 is greater than the specified precision requirement.

If the equation has roots, and the approximate root sequence converges by the above method, then the x0 obtained by the above method is considered to be the root of the equation. The above algorithm is expressed in the form of a C program:

The "algorithm" iterative method to find the root of the equation

The following is a reference fragment:

{x0= initial approximate root;

do{

x1=x0;

X0=g (x1);/* Calculates a new approximate root by a specific equation */

}while (Fabs (x0-x1) >epsilon);

printf ("The approximate root of the equation is%f\n", x0);

}

The iterative algorithm is also often used to find the root of the equation group, so

x= (x0,x1,...,xn-1)

The set of equations is:

Xi=gi (X) (i=0,1,...,n-1)

The iterative algorithm for solving the root of the equation can be described as follows:

The "algorithm" iterative method to find the root of the equation group

The following is a reference fragment:

{for (i=0;i

x= initial approximate root;

do{

for (i=0;i

Y=x;

for (i=0;i

X=gi (X);

for (delta=0.0,i=0;i

if (Fabs (y-x) >delta) delta=fabs (y-x);

}while (Delta>epsilon);

for (i=0;i

The approximate root of printf ("Variable x[%d" is%f ", i,x);

printf ("\ n");

}

The following two possible scenarios should be noted when using iterative methods for root-finding:

⑴ if the equation is not solved, the approximate root sequence obtained by the algorithm will not converge, and the iterative process will become a dead loop, so before using the iterative algorithm, we should first investigate whether the equation has a solution and limit the number of iterations in the program.

Although the ⑵ equation has a solution, the iterative formula selection is inappropriate, or the initial approximate root selection of the iteration is unreasonable, which can lead to the failure of the iterative generation.

①n is the number of rabbits, M is the month (n+n*1) ^m-1=2n^m-1 (note)

Introduction to Iterations-from Sogou encyclopedia

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.