Reputation: 311
I have encountered a problem with matlab when trying to generate uniform r.v.(random variables)
As shown in the plot, the histogram of the generated r.v.s are not really 'uniform' at the boundaries, in my case, 0
and 2*pi
.
I hope the graph can be opened. Because of the low reputation, sadly I'm not able to post images.
and i simply used the following code:
phi = rand(Ndistur,Nsim)*(2*pi);
Either solutions or ideas are welcome.
Upvotes: 0
Views: 1690
Reputation: 124563
It could be that you have a mistake in the way you generate the histogram. Consider this code:
x = rand(50000,1)*2*pi;
[count bins] = hist(x,64);
bar(bins,count,'hist')
xlim([-1 7])
Upvotes: 1
Reputation: 46882
It looks like the binning may be wrong in your graph.
At the lower end you probably have a bin for -0.05 to 0.05, and since the range of values starts at 0.0 that will be half empty.
At the upper end, the data should go to 6.28, but the last bin looks like it is probably 6.15-6.25 so could be over-populated if you are placing everything greater than 6.25 in there.
Upvotes: 5