Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11808 > unrolled thread

while loop through a list

Started by"tarpanelli@libero.it" <tarpanelli@libero.it>
First post2012-09-19 08:56 +0000
Last post2012-09-21 18:07 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  while loop through a list "tarpanelli@libero.it" <tarpanelli@libero.it> - 2012-09-19 08:56 +0000
    Re: while loop through a list Ray Koopman <koopman@sfu.ca> - 2012-09-21 18:07 +0000

#11808 — while loop through a list

From"tarpanelli@libero.it" <tarpanelli@libero.it>
Date2012-09-19 08:56 +0000
Subjectwhile loop through a list
Message-ID<k3c1co$eur$1@smc.vnet.net>
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

[toc] | [next] | [standalone]


#11837

FromRay Koopman <koopman@sfu.ca>
Date2012-09-21 18:07 +0000
Message-ID<k3iack$ssb$1@smc.vnet.net>
In reply to#11808
On Sep 19, 1:58 am, "tarpane...@libero.it" <tarpane...@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}

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web