MathGroup Archive 2003

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

Search the Archive

Re: now, while loops construct errors

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44306] Re: now, while loops construct errors
  • From: poujadej at yahoo.fr (Jean-Claude Poujade)
  • Date: Wed, 5 Nov 2003 10:00:29 -0500 (EST)
  • References: <bo5sfg$m9$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

sean kim <sean_incali at yahoo.com> wrote in message news:<bo5sfg$m9$1 at smc.vnet.net>...
> 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}]
> 
The test is a 'go on' test and your dv module should therefore
be written this way :

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

---
jcp


  • Prev by Date: Re: Integrate...
  • Next by Date: Re: Plot&2backgroundcolors
  • Previous by thread: Re: now, while loops construct errors
  • Next by thread: Re: now, while loops construct errors