randn function does not work

조회 수: 7 (최근 30일)
Binbin Zhang
Binbin Zhang 2017년 11월 27일
댓글: David Goodmanson 2017년 11월 27일
the average value of data generated by function 'randn' is not zero
  댓글 수: 1
Stephen23
Stephen23 2017년 11월 27일
편집: Stephen23 2017년 11월 27일
It doesn't have to be. What would you expect for a random sample of one?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 27일
Any one call to randn() is a finite sampling of the infinite distribution. The mean of 0 is statistical, not guaranteed for any finite subset.
If it were otherwise, imagine doing randn(1,1): in order for the mean of that sampling to be 0 each randn(1,1) would have to return 0. For randn(1,2) with two values being generated, both would have to be 0 or the two would have to be exact negatives of each other.
You can do statistical modeling to figure out the probability of the mean of a finite sampling being more than any given value.

추가 답변 (2개)

Guillaume
Guillaume 2017년 11월 27일
For some reason, my dice don't work either. I've thrown them many times, yet the mean value is not exactly 3.5.
>> mean(randn(1, 1e8))
ans =
-1.9019e-04
Pretty close to zero if you ask me. You'll only get exactly zero if you call randn an infinite number of times (or you're really lucky)

Binbin Zhang
Binbin Zhang 2017년 11월 27일
Thanks a lot, got it.
  댓글 수: 1
David Goodmanson
David Goodmanson 2017년 11월 27일
Somebody should mention that if you take N samples from a distribution with standard deviation 1, then the standard deviation of the N-sample mean is 1/sqrt(N). So in Guillaume's example with N = 1e8, you would expect an answer down around 1e-4, which is what happened.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 均匀分布(连续)에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!