Re: NestWhile
- To: mathgroup at smc.vnet.net
- Subject: [mg37887] Re: NestWhile
- From: atelesforos at hotmail.com (Orestis Vantzos)
- Date: Sat, 16 Nov 2002 01:16:20 -0500 (EST)
- References: <ar24f4$fpi$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hader Josef <e9426270 at stud4.tuwien.ac.at> wrote in message news:<ar24f4$fpi$1 at smc.vnet.net>...
> Hi folks,
> maybe you can help me with the following problem:
>
> there is an iterative function
> f[x_]:=.... resulting something like {values, boolean}
>
> I would like to nest f onto f repetitativly, however the number is not
> fixed in the beginning, but depends on the output of f (the boolean
> value).
> it looks like:
> NestWhile[f[#] &, {init,true}, criteria (depending on the output of f, 10]
>
> any hint???
> thank you
> h.
Just an example...
In[1]:=
f[{x_,_}]:=With[{val=x+Random[]},{val,val>=5}]
In[3]:=
NestWhileList[f,{0,True},Last]
Out[3]=
{{0,True},{0.818349,True},{1.47905,True},{2.1265,True},{2.33135,
True},{2.79274,True},{3.24593,True},{3.96528,True},{4.17204,True},{5.0755,
False}}
By the way, I can't see why you couldn't transfer the criterion on the
last argument of NestWhile (or NestWhileList) and have f return the
value alone...
Orestis Vantzos