Computing Variance manually problem

3 visualizzazioni (ultimi 30 giorni)
HI all I am facing a problem in computing variance manualy.As
I have a A= magic(3) matrix of 9 elements
when I calculate it directly by using var it gives me
var(var(A)) ans is 27 but when I campute manually it does not match with above answer
As
variance=(A-mean(mean(A))).^2/8 variance=sum(sum(variance)) answer is 0. why is this situation occurring is there any problem in my formula?

Risposta accettata

Shashank Prasanna
Shashank Prasanna il 23 Gen 2013
Your formula is wrong. when you say var(var(A)) you are actually computing the variances of each column and then variances of these variances. Is there a reason you are doing this? However if you are interested in reproducing the result, then you have to follow the same steps manually as follows:
A = magic(3);
B = sum((A-repmat(mean(A),3,1)).^2)/2; % Variance of each column
var_magic = sum((B-mean(B)).^2)/2 % Variance of the variance computed above.
var_magic =
27
  1 Commento
Algorithms Analyst
Algorithms Analyst il 23 Gen 2013
Thannk you.yes thre is some reason for doing it thank you...

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by