- I want to learn Multivariate Gussian distribution so I written the following code.*I am implementing following formula http://upload.wikimedia.org/math/a/0/a/a0ad9db46854c4a616ce6959095cf21d.png
Iam expecting this type of plot
Where I am doing mistake?
clear allclc% Taking two guassian random variables
x=randn(1000,1);y=randn(1000,1);X=[x y];X=X';d=size(X,1);% find means of x,y
mx=mean(x);my=mean(y);mumat=[mx my]';mumat=repmat(mumat,1,size(X,2));Dif_mat=X-mumat;% The above step (Dif_mat) is (X-mu) in the formula
cov_mat=cov(X'); % covariance matrix
det_cv=det(cov_mat); % det of cov matrix
inv_cov=inv(cov_mat); % inverse of cov matrix
% scale term before exp in forumala
scale=((2*pi)^(d/2))*sqrt((abs(det_cv))); scale=inv(scale);% Mahabolis distance in formula
MB=Dif_mat'*cov_mat*Dif_mat;% find the final probability
p=scale*exp((-1/2)*MB);surf(x,y,p)
Answer this question please!
Best Answer