simple quastion about randn and mean of random noise
Mostrar comentarios más antiguos
hi, i'm a bit confused and need your help.
i know that mean(sum(n))=sum(mean(n)) where n is a random noise with zero mean and N0 variance.
but when im writing : n=randn(1000,1)
mean(sum(n))=-32.... sum(mean(n))=~0
whats the diference and how its get along with E(sum(n))=sum(E(n))??
thanks in advance...
Respuesta aceptada
Más respuestas (2)
Matt Tearle
el 28 de Jul. de 2011
0 votos
n = randn(1000,1) creates a vector (1000-by-1), so sum(n) is the sum of the thousand random numbers. Taking the mean is then the mean of a single value (ie the value itself).
Similarly, mean(n) calculates the mean of the 1000 numbers (should be about 0), then sum adds that one number.
Perhaps you wanted to do n = randn(1000); instead? Then mean(sum(n)) and sum(mean(n)) will be equal to within roundoff.
the cyclist
el 28 de Jul. de 2011
I believe that the first mathematical statement you wrote is intended to be a statement about two different distributions. The MATLAB code you wrote was just one instance, so I am not sure how helpful that is.
Here is some code that might help you visualize what is going on. It is related to what Rick wrote. The math statement seems intuitively correct to me, but I'd have to think carefully about it. My code suggests that the two sides of the equation do not actually have the same distribution.
NTIMES_TO_TEST = 2000;
SAMPLESIZE = 1000;
NTRIALS_OF_SAMPLE = 500;
[meansum,summean] = deal(nan(NTIMES_TO_TEST,1));
for nt = 1:NTIMES_TO_TEST
if round(nt/100)==(nt/100)
disp(['Iteration: ',num2str(nt),' out of ',num2str(NTIMES_TO_TEST)])
end
r1 = randn(SAMPLESIZE,NTRIALS_OF_SAMPLE);
r2 = randn(SAMPLESIZE,NTRIALS_OF_SAMPLE);
meansum(nt) = mean(sum(r1));
summean(nt) = sum(mean(r1));
end
NBINS = 25;
figure
subplot(2,1,1), hist(meansum,NBINS)
set(gca,'XLim',[-4 4])
title('Distribution of mean of sum')
subplot(2,1,2), hist(summean,NBINS)
set(gca,'XLim',[-4 4])
title('Distribution of sum of mean')
Categorías
Más información sobre Descriptive Statistics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!