Equal probability in 'randsrc(m,n)' in-built function
1 view (last 30 days)
Show older comments
Hi, we have an in-built function called 'randsrc(m,n)', where ideally it should generate an m-by-n matrix, each of whose entries independently takes the value -1 with probability 1/2, and 1 with probability 1/2.
Problem: I have used randsrc(1,3072), where I should get number of +1's and -1's as 1536 each.I am not getting equal number of +1's and -1's
Please help me in finding out the solution for this.
Regards, Sowmya.
0 Comments
Answers (1)
Tom Lane
on 28 Mar 2012
I have no idea what your function is or if it does things correctly. But from your description you would not expect exactly 1536 +1's each time. The number should vary according to a binomial distribution. Otherwise your values are not independent or not random.
If you have the Statistics Toolbox, there are function with names starting with "bino" that you might use to help decide if your results are reasonable. For example, here is an interval that you'd expect to contain roughly 98% of the values:
>> binoinv([.01 .99],3072,.5)
ans =
1472 1600
The standard deviation of the result should be about sqrt(3072/4) = 27.7.
0 Comments
See Also
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!