Tools for Analyzing Discrete Dynamical Systems:
Iterating Functions
Written by Richard A. Holmgren
last modified June 18, 1996

These programs were developed for use with the text  A First Course in Discrete Dynamical Systems, 2nd edition by Richard A. Holmgren, which was published by Springer-Verlag in 1996.    Suggestions for improvement are gratefully accepted.  Please contact Professor Holmgren at rholmgre@alleg.edu with suggestions and comments.

Iterating Functions

The easiest way to iterate functions with Mathematica is to use the Nest[...] command.   The format is Nest[ function, start value, number of iterations].  For example, below we define 
f(x) = x3 and then iterate f(x) three times starting at 1.2.

Clear[f];
f[x_] := x^3;
Nest[f,1.2,3]

NestList[...] will show the value of the first n iterates.  The format is similar.  Below we see the first three iterates of 1.2  under f(x) = x^3.

Clear[f];
f[x_] := x^3;
NestList[f,1.2,3]

The formatting command TableForm[...] can make the output of NestList[...] easier to read, especially for long lists.

Clear[f];
f[x_] := x^3;
TableForm[NestList[f,1.01,8]]

Creating Tables of Iterates.

The following set of commands determine how a given value  changes under iteration of a function by generating a table of values with the number of iterations represented in the first column.  Note that we may not want to print the first few iterations since it may take the a awhile for the iteratiosn to settle reach an attracting orbit.  In the following example, the iterations seem to be approaching an attracting perioid two orbit.  In the first two lines we define the function.   Next  we tell the computer what our starting value is and in the fourth and fifth lines we  tell the computer which iterations to print.

Clear[h];
h[x_]:= 3.2x(1-x);

StartingValue = .1;
FirstIteration = 20;
LastIteration = 30;

i=0;
y = N[StartingValue];
While[i <= LastIteration,
    If[i >= FirstIteration,
        Print[i,"\t  ",N[y,8]]];
    y = h[y];
    i = i+1]

Controlling the precision of a calculation

For some of the exercises in the text we need be able to control the precision of the computations.    The Mathematica command SetPrecision[number, n] writes number to n significant digits, adding zeros or rounding as necessary.  Zeros which are added are in binary so the base ten representation of the new number will not necessarily end in  zeros.  The variable SigDigits controls the amount of rounding.

Clear[h];
h[x_]:= 3.2x(1-x);

StartingValue = .1;
FirstIteration = 10;
LastIteration = 20;
SigDigits = 16;

i=0;
y = SetPrecision[StartingValue,SigDigits];
While[i <= LastIteration,
    If[i >= FirstIteration,
        Print[i,"  ",N[y,8]]];
    y = SetPrecision[h[y],SigDigits];
    i = i+1]

Graphing Iterated Functions

The following set of commands plots the 2nd iterate of  h(x) and the line y=x on the same graph.   The variables xmax and xmin are maximum and minimum limits for the graphed domain and range of h(x).  The variable NumberOfIterations should be self-explanatory.

Clear[h];
h[x_]:= 3.2x(1-x);
xmin = 0  ;
xmax = 1  ;
NumberOfIterations = 2  ;

Plot[{Nest[h,x,NumberOfIterations],x},{x,xmin,xmax},
	PlotRange->{xmin,xmax},
	AspectRatio->1]

Exercises

1)  Does h(x) have any points of period 2?  What is the significance of the points of intersection of the graph of the line y=x and the graph of  the nth iterate of  the function h(x)?

2)  Using the above procedure determine whether or not h(x) has any points of prime period 4.

3)  Using the graphing command above, determine the periodic points  of the function 
h(x) = 3.5x(1-x).