randi generate a normally distributed integer matrix
이전 댓글 표시
I encountered a problem while studying the courses officially provided by matlab. The question requires using the randi function to generate a normally distributed rather than uniformly distributed integer matrix. After consulting the help file of the randi function, I did not find this function.
댓글 수: 4
Steven Lord
2023년 10월 25일
Could you share in which section of which course you see that instruction?
Bruno Luong
2023년 10월 25일
It sounds like a mistake, normal distribution is continuous distribution, not discrete. So either RANDI or NORMAl stated in the course is incorrect.
Dyuman Joshi
2023년 10월 25일
You might have misread it as integers rather than numbers.
However, this is only a guess. For a definite feedback, please provide the information @Steven has asked in the comment above.
John D'Errico
2023년 10월 26일
편집: John D'Errico
2023년 10월 26일
Can you use randi to generate a normally distributed matrix? Of course not. You may be mistaken. Or the person writing the question may have not understood what they are asking. After all, people are only human. Even those who write questions as part of courses or textbooks, even teachers.
You could use randi as part of something to generate a sample that will APPROXIMATE a normal distribution, with some effort. I can think of several ways to do that.
If you can show/quote the actual quetion, we might be able to help you. But doing what you seem to think you want to do is not possible.
답변 (1개)
The following illustrates that it is possible to create an array of integers whos population statistics approximate normal distribution. The larger the population generated, the more the array (here called discrete) would approximate normal distribution.
This does not show you anything about how to create such a distribution starting with randi() -- just that there are meaningful senses in which it could exist.
rng('shuffle')
N = 1000;
continuous = randn(N,1);
scalefactor = (2^53 - 1);
bins = -1:.1:1;
discrete = round(continuous * scalefactor);
descaled = discrete ./ scalefactor;
sdc = std(continuous)
sdd = std(descaled)
sdi = std(discrete)
r = sdi / sdc
scalefactor / r
histogram(continuous, bins)
histogram(descaled, bins)
histogram(continuous - descaled)
histogram(discrete, bins*scalefactor)
[H,P,CI,STATS] = ttest2(continuous, descaled)
댓글 수: 2
One could use the well known central limit theorem, no need to mess with number bit coding and poor results.
But that is not the point. It is still not a normal distribution strictly speaking
n=1000000;
ns=100; % larger -> better approximation
r=sum(randi([-1000 1000],ns,n))/(sqrt(sum((-1000:1000).^2)*ns/(2001)));
histogram(r,'Normalization','pdf');
x=linspace(-3,3);
hold on
plot(x,1/sqrt(2*pi)*exp(-x.^2/2),'g','linewidth',2)
Walter Roberson
2023년 10월 26일
Any finite sampling of normally distribute samples will not be normally distributed "strictly speaking".
카테고리
도움말 센터 및 File Exchange에서 Uniform Distribution (Continuous)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




