Why is the mean function not working?

6 Ansichten (letzte 30 Tage)
Porgs
Porgs am 5 Mai 2018
clc
x=randn(1,100000);
y=randn(1,100000);
Za=x+10;
[f,x]=hist(Za,100); %Simulated PDF
bar(x,f/trapz(x,f));
hold on;
title('normalized histogram');
ym = mean(Za)
yv = var(Za)
  2 Kommentare
per isakson
per isakson am 5 Mai 2018
Bearbeitet: per isakson am 5 Mai 2018
What do you mean by "function not working"?
Here, R2016a, your code works according to my expectations.
dpb
dpb am 5 Mai 2018
Sometime you've probably inadvertentedly written mean on the LHS and aliased the function...see what
which mean
returns and try
clear mean
and see if symptoms don't disappear. (The new Crystal Ball Toolbox)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 5 Mai 2018
I am not sure why you say that mean() is not working.
Perhaps you are figuring that the mean of the normal distribution is 0, and that when you add 10 to that, you should get a mean of exactly 10 of the result.
If so then the difficulty with that is that randn() is not the theoretical continuous normal random generator: it is the discrete normal random generator, which emits particular samples that are statistically uniform random in distribution.
The situation is exactly like flipping a single coin and expecting that the result will be a half head and a half tail because that is the long term statistical mean result. Any one coin flip must give a particular result, and although the long term statistical results will tend to 1/2 heads and 1/2 tails, the short term results will likely not be exactly balanced. It is "the Gambler's Fallacy" -- the statistics have no "memory" and probably will not exactly balance over any finite length of time.
If you want to work with theoretical continuous generators to know the theoretical statistical means instead of the discrete means over a given set of samples, then you need to use the continuous generation functions in the Statistics Toolbox.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by