Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: while loop through a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128174] Re: while loop through a list
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Fri, 21 Sep 2012 04:13:04 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <k3c1co$eur$1@smc.vnet.net>

On Sep 19, 1:58 am, "tarpane... at libero.it" <tarpane... at libero.it>
wrote:
> Hello
> i've this problem to solve:
>
> let us suppose I've  a function f which returns a random number and I start
> with an intial list of n random number
> I would like to check if each one of the element of this list is below zero
> and if it is applies the function f till when the new random number is above 0.
> This should be repeated for each element of the list such that at the end all
> the list random numbers will be above 0.
>
> Thanks in advance ,
> Paolo

f[] := RandomReal[{-1,1}]

t = Table[f[],{n = 5}]

{-0.654401,0.694079,0.141754,0.163587,-0.418953}

NestWhile[f[]&,#,Negative]& /@ t

{0.917314,0.694079,0.141754,0.163587,0.227141}



  • Prev by Date: Does FindCurvePath work?
  • Next by Date: Re: Exact Schur Decomposition
  • Previous by thread: Re: while loop through a list
  • Next by thread: Weighting in simultaneous NonlinearModelFits