Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NestList

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50583] Re: NestList
  • From: p-valko at tamu.edu (Peter Valko)
  • Date: Sat, 11 Sep 2004 06:44:33 -0400 (EDT)
  • References: <chpa26$jt6$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Nemrata,

I am suggesting a solution:


fun1[x_,n_]:=(Print["now I know that n=",n];fun[x]);
Last[FoldList[fun1,x,Range[3]]]


now I know that n= 1
now I know that n= 2
now I know that n= 3

fun[fun[fun[x]]]


Peter


Namrata Khemka <namrata.khemka at gmail.com> wrote in message news:<chpa26$jt6$1 at smc.vnet.net>...
> Hello everyone,
> 
> I have a question regarding NestList function. 
> 
> I am applying a function on the expression n times.
> 
> NestList [function, expr, n]
> 
> However in my function I would like to know what is the current value
> of n. In other words I would like to know what iteration it is on.
> 
> Is this possible?
> 
> Thanks in advance.
> 
> Namrata Khemka


  • Prev by Date: Evaluating integral for magnetic field intensity using mathematica
  • Next by Date: Re: Cell write protect?
  • Previous by thread: Re: Re: NestList
  • Next by thread: Matrix calculation causes memory usage to jump