Re: Creating List of Sequence Iterates

• To: mathgroup at smc.vnet.net
• Subject: [mg33397] Re: [mg33385] Creating List of Sequence Iterates
• From: BobHanlon at aol.com
• Date: Wed, 20 Mar 2002 01:52:59 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```In a message dated 3/19/02 1:11:39 AM, nitlion at mindspring.com writes:

>I'm trying to figure out how, with a single expression, I can create a
>list
>of iterates of some sequence.
>
>For example, suppose I have defined F[x_] := 3x+2 and I want to get a list
>that contains F[1], F[F[1]], F[F[F[1]]], etc.  It seems like I could do
>something like
>
>    iterates = Table [F[ iterates[[n-1]] ] , {n,1,20}]
>
>to get a list of the first 20 iterations of this function (assuming I had
>some way to define interates[[1]]).
>
>Anyone know how I can do that, short of writing the following function?
>
>  Iterate[func_ , first_ , iterations_] := Module[ {v, ix},
>    v = Table[0, {n, 1, iterations}];
>    v[[1]] = first;
>
>    For[ix=2, ix<=iterations, ix++, v[[ix]] = func[v[[ix-1]]] ];
>
>    v
>    ]
>
>Any help would be appreciated.  I'm mostly interested in being pointed
>in the right direction.
>

Use NestList

Clear[f,n,x];
n=3;

NestList[f, x, n]

{x, f[x], f[f[x]], f[f[f[x]]]}

f[x_] := 3x+2;

NestList[f, f[x], n]//Simplify

{3*x + 2, 9*x + 8, 27*x + 26, 81*x + 80}

Bob Hanlon
Chantilly, VA  USA

```

• Prev by Date: Re: newbie question - printing Pi
• Next by Date: help!! Clueless on how to proceed...
• Previous by thread: Re: Creating List of Sequence Iterates
• Next by thread: Re: Creating List of Sequence Iterates