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

MathGroup Archive 2010

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

Search the Archive

Re: A distribution problem using Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111499] Re: A distribution problem using Mathematica
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Tue, 3 Aug 2010 06:40:14 -0400 (EDT)
  • References: <i368np$r7k$1@smc.vnet.net>

On Aug 2, 4:04 am, "S. B. Gray" <stev... at ROADRUNNER.COM> wrote:
>         I want 3 random variables v1,v2,v3 with uniform distribution from 0 to
> 1, but modified or normalized so that their sum is a uniform
> distribution from 0 to 1.
>         These variables are for placing a point at a random place inside a
> tetrahedron defined by 4 vertex vectors p1,p2,p3,p4. The internal point
> is given by p=v1(p1-p4)+v2(p2-p4)+v3(p3-p4) (barycentric coordinates).
> The 0 to 1 constraints assure that the point p will be inside.
>         The  closest I have come is this function giving the triplet
> frs={v1,v2,v3}:
>
>   mul = RandomReal[{0, 1}, {3}];
>   mul = mul/Total[mul];
>   frs = Sqrt[RandomReal[{0, 1}, {3}]]*Power[mul, (3)^-1];
>
> which I tested with the histogram nhist: (The +1 avoids trying to access
> the 0th element of the list nhist.)
>
> nhist = Table[0, {1000}];
> Do [ mul = RandomReal[{0, 1}, {3}];
>       mul = mul/Total[mul];
>       frs = Sqrt[RandomReal[{0, 1}, {3}]]*Power[mul, (3)^-1];
>       ip  = IntegerPart[1000 frs][[2]];
>       nhist[[ip+1]]++, {10000}
>     ];
> Print[frs];
> ListPlot[nhist]
>
> This ad-hoc method gives a distribution that covers the range 0-1 but is
> too heavy in the region 0.3 to 0.7. This would put too many points near
> the middle of the tetrahedron. Something tells me there must be a better
> and more elegant solution. Any ideas?
>
> Steve Gray

Further to my earlier post, this should be a little faster:

#.p/Total[#,{2}]&@RandomReal[ExponentialDistribution[1],{n,m+1}]


  • Prev by Date: Re: Mathematica- Use a previous equation into the function Function
  • Next by Date: Re: ReplaceAll and ReplaceRepeated Strange Behavior
  • Previous by thread: A distribution problem using Mathematica
  • Next by thread: Re: A distribution problem using Mathematica