Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*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 2003

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

Search the Archive

now, while loops construct errors

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44254] now, while loops construct errors
  • From: sean kim <sean_incali at yahoo.com>
  • Date: Fri, 31 Oct 2003 03:01:25 -0500 (EST)
  • Reply-to: sean_incali01 at yahoo.com
  • Sender: owner-wri-mathgroup at wolfram.com

hello group. 

ok. Long post once again. with multiple part question.


part 1. 

now I have problems with constructing a while loop
under contraint. 

This post also deals with picking random numbers under
a constraint. (I need to do this for a solve routine I
have developed for an ode system)

Peter and Daniel has used "While" effectively with
previous post, so I thought I would just modify their
codes to come up with something suits my needs in this
case. but it's not working out as i hoped. 

I'm trying to pick randome numbers for a pair such
that the ratio of the two random numbers picked are
between a range given. 

So with v1 and d1, the ratio has to be between 10^-8
and 10^-4. I have implemented this as follows. 

In[395]:=
dv:= Module[{v1n, d1n}, 
While[
(v1n=10^ Random[Real,{-12,-7}]); 
(d1n=10^ Random[Real,{-6,-4}]); 
10^-8<= (v1n/d1n)<= 10^-4 ];
{v1 -> v1n, d1 -> d1n, v1n/d1n//ScientificForm}]

Do[Print[dv], {n, 1, 10}]

above will pick random numbers and make the rule and
then print the ratio. ( "Do" will print it 10 times)

this seems to work at the first glance,  but not
really since it doesn't really do the random number
generation under the given constraint. 

the constraint was that the ratio has to be between
10^-8 to 10^-4 ( for other cases, I have smaller
ranges for the constraint)

but quite often, i get ratios that are way out of the
range given.  below is one example... 

Out[244]= {v1->2.49351 x 10^-8, d1->1.59411 x 10^-6,
1.56421 x 10^-2}

last number(1.56421 x 10^-2) is the ratios between the
v and d, and it is clearly out of the range of 10^-8
to 10^-4. Obviously i'm not doing something right. 
 
How do I fix this so that the routine picks under a
given constraint?


part2. 

what exactly is the difference between the following
three repesentation of a range? (Peter suggested that
i use the first represntation, and i'm starting to see
why but i don't understand it) 

In[90]:=
{10^ Random[Real,{-12,-6}],
Random[Real,10^{-12,-6}],
Random[Real,{10^-12,10^-6}]}

upon repeat evaluating, it's easy to see that the
first representation gives number over wider range
while the other two stays within very short range.( in
the order of 10^-7)

Out[108]= 
{6.07721 x 10^-11, 3.82330 x 10^-7, 5.49021 x 10^-7}

Out[109]=
{1.02699 x 10^-8, 6.28981 x 10^-7, 3.37704 x 10^-7}

Out[110]=
{8.50961 x 10^-9, 9.98681 x 10^-7, 1.71181 x 10^-7}

any and all thoughts are greatly appreciated.( again)

thanks in advance. 

sean 

__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/


  • Prev by Date: Re: Integrate 5.0
  • Next by Date: Re: reduced functionality of Solve
  • Previous by thread: Re: Integrate 5.0