|
[Date Index]
[Thread Index]
[Author Index]
Re: Beginner--Help on Listing Values
- To: mathgroup at smc.vnet.net
- Subject: [mg74940] Re: [mg74919] Beginner--Help on Listing Values
- From: Darren Glosemeyer <darreng at wolfram.com>
- Date: Thu, 12 Apr 2007 04:48:51 -0400 (EDT)
- References: <200704110558.BAA02825@smc.vnet.net>
m.lungay at gmail.com wrote:
> I need to create a list of probability values for a certain random variable X. It is very difficult if i keep on enumerating the entries especially when the length required is large, say the list is of length 100. Maybe there is some way where I could generate the entries in a random manner. There is a code Random[], but how could I implement it in a List manner so that the sum of the results must be 1. Please help!
>
>
>
> Link to the forum page for this post:
> http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Special:Forum_ViewTopic&pid=17333#p17333
> Posted through http://www.mathematica-users.org [[postId=17333]]
>
>
>
It is not clear from the message what the nature of the random variable
X is. Assuming you want a list of n uniformly distributed random values
that sum to 1, you could generate n values via Random[] and then divide
those values by their total. Here is an example with n==10.
In[1]:= rvals = Table[Random[], {10}]
Out[1]= {0.432052, 0.540504, 0.925453, 0.0643451, 0.650853, 0.614416,
0.827691, 0.557976,
> 0.432144, 0.1755}
In[2]:= rvals/Total[rvals]
Out[2]= {0.0827537, 0.103526, 0.177258, 0.0123244, 0.124662, 0.117683,
0.158533, 0.106873,
> 0.0827714, 0.0336146}
In[3]:= Total[%]
Out[3]= 1.
The following probList function could be used to generate a list of
length n.
In[4]:= probList[n_] := With[{rvals = Table[Random[], {n}]},
rvals/Total[rvals]]
In[5]:= probList[20]
Out[5]= {0.0765762, 0.0652854, 0.070426, 0.0266055, 0.0139826, 0.011429,
0.00404757,
> 0.0716607, 0.0370334, 0.0251732, 0.0643284, 0.072781, 0.0637495,
0.0785196,
> 0.0290183, 0.0286076, 0.069842, 0.0732609, 0.0575529, 0.06012}
In[6]:= Total[%]
Out[6]= 1.
Darren Glosemeyer
Wolfram Research
Prev by Date:
Re: Marking pivot elements in a matrix?
Next by Date:
Re: Marking pivot elements in a matrix?
Previous by thread:
Beginner--Help on Listing Values
Next by thread:
Re: Beginner--Help on Listing Values
|