Computing Variance manually problem

8 views (last 30 days)
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?

Accepted Answer

Shashank Prasanna
Shashank Prasanna on 23 Jan 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 Comment
Algorithms Analyst
Algorithms Analyst on 23 Jan 2013
Thannk you.yes thre is some reason for doing it thank you...

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!