I want to generate multivariate normal joint distribution for a 3*3 matrix. Say I have mu = [0.4 0.5] and sigma = [0.25 03; 0.45 0.5]. As I wanted to generate a 3*3 joint distribution, I decided to do the following:
mu = [0.4 0.5];sigma = [0.25 0.3; 0.3 0.5];x1 = 1:3;x2 = 1:3;[X1,X2] = meshgrid(x1,x2);X = [X1(:) X2(:)]; y = mvnpdf(X,mu,sigma);
My assumption is that X now has 3*3 matrix index. If the value is 3 1 it means X = 3, Y = 1. For example, if I print the value of X I get:
1 11 21 32 12 22 33 13 23 3
So, my assumption was the final pdf will be a 9*1 vector and each value will represent the probability of each row. For example, if the second value is 0.05, it will indicate P(X=1,Y=2) = 0.05.
When I gey y, I get the following:
y = 0.3484 0.0471 0.0000 0.0000 0.0027 0.0015 0.0000 0.0000 0.0000
However, as y is a joint distribution, the sum(y) should have been 1. But here it's 0.3997.
Can anyone tell me what am I doing wrong here? And why the sum is not 1?
Best Answer