Iter is a package of simple tools for studying the sequences a, f(a), f(f(a)), f(f(f(a))), ... obtained by repeatedly applying a function f to an initial value a. To iterate something is to do it repeatedly.

Use iter( f, n, a ) to compute the sequence which begins with a, f(a), f(f(a)) ... and has a total of n+1 terms.

Use iterprint( f, n , a ) to apply f to a n times and print the results in vertical format.

Use iterplot( f, n, a ) instead of iterprint to plot the sequence a, f(a), f(f(a)), ...

Use iterplot( f, g, n, a ) to plot the sequences a, f(a), f(f(a)), ... and a, g(a), g(g(a)), ...

Use cobweb( f, n, s, a..b ) to show how the sequence of iterates s, f(s), f(f(s)) is generated by the "cobweb" procedure.

Use printarray(y) to print a list y in vertical format.

Source Code (You can copy this from your browser and paste it into Maple).

Example 1

Define a function
double := x -> 2*x;
iterprint( double, 4, 1 );
applies double a total of four times to compute and print the sequence 1, 2, 4, 8, 16. The command
iterplot( double, 4, 1 );
computes the same sequence but displays a plot of it instead of "printing."

Note: If you need to store the sequence for later manipulation, try

results := iter( double, 4, 1 );
To display this variable use print(results) or printarray(results).

Example 2

The quadratic function f(x) = kx(1-x) gives more interesting results.
quad := x -> k*x*(1-x);
k := 3.0;
iterplot( quad, 40, 0.1 );

k := 4.0;
iterplot( quad, 40, 0.1 );
Try different values of the parameter k and the initial value. Use k in the range 1 to 4 and the initial value in the range 0 to 1.

Example 3

With iterplot2 you can compare two different sequences, e.g., the ones generated by quad with different initial values.
iterplot2( quad, quad, 40, 0.1, 0.9 );

Example 4

The function "cobweb" is useful for demonstrating graphicaly how a map is iterated. It is also useful for for finding fixed points. Try
k := 2.5; cobweb( quad, 10, 0.1, 0..1 );
This example "cobwebs" quad 10 times on the interval 0..1 with an initial value of 0.1.

Example 4

The iter function can be used to implement Newton's method for finding roots. Let us use it to find the square root of two, which is a root of the quadratic function
f := x -> x*x - 2;
Newton tells us to iterate the function
g(x) = x - f(x)/f'(x)
with a reasonable guess for the starting value. Try the example below, which iterates g 10 times with 1 as initial value.
g := x -> (x*x + 2)/(2.0*x);

iterprint( g, 10, 1 );