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

MathGroup Archive 2008

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

Search the Archive

Re: Don't understand replacement rule for some functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89562] Re: [mg89538] Don't understand replacement rule for some functions
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Fri, 13 Jun 2008 06:07:48 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

SeedRandom[1]

RandomReal[GammaDistribution[L, 1/L], 2] /. L -> 3

RandomReal::parpos: The parameter L in position 1 of GammaDistribution[L,1/L] \
should be positive >>

{0.316614,0.610561}

RandomReal evaluates with your symbolic argument and fails. After the failure, the replacement causes a second evaluation which is successful. To avoid the error notice, you want the replacement to occur prior to evaluating RandomReal. Consequently, use

SeedRandom[1]

RandomReal[GammaDistribution[L, 1/L] /. L -> 3, 2]

{0.316614,0.610561}


Bob Hanlon

---- Mac <mwjdavidson at googlemail.com> wrote: 
> Can somebody explain why the following replacement rule works
> 
> In[15]:= f[x] /. x -> y
> 
> Out[15]= f[y]
> 
> and this one complains
> 
> In[14]:= RandomReal[GammaDistribution[L, 1/L], 2] /. L -> 3
> 
> During evaluation of In[14]:= RandomReal::parpos: The parameter L in \
> position 1 of GammaDistribution[L,1/L] should be positive >>
> 
> Out[14]= {1.89311, 1.11748}
> 
> I find it quite elegant to use replacements for complicated functions
> but I'm never quite sure whether the replacement is actually carried
> out because of such behavior.
> 
> Many thanks again for your help.
> 
> Mac
> 



  • Prev by Date: Manipulate: Positioning of controls within panel
  • Next by Date: Fonts in publication quality figures.
  • Previous by thread: Re: Don't understand replacement rule for some functions
  • Next by thread: Re: Don't understand replacement rule for some functions