Bivariate Normal Distribution different for expression and mvnpdf()
古いコメントを表示
Hi,
I am plotting 3D graph of bivariate gaussian distribution using 2 methods for the same range of x and y but still i am getting different results.
Method 1:
figure6b = figure('Name','Figure 1 ','NumberTitle','off');
mu = [0 ,0];
sigma = [0.5 0.8; 0.8 2.0];
x1 = -3:0.2:3;
x2 = -3:0.2:3;
x = [x1; x2];
[X1,X2] = meshgrid(x1,x2);
X = [X1(:) X2(:)];
y = mvnpdf(X,mu,sigma);
y = reshape(y,length(x1),length(x2));
surf(X1,X2,y)
xlabel('x')
ylabel('y')
zlabel('Bivariate Gaussian Distributions')
Output:

Method 2:
figure6b = figure('Name','Figure 2 ','NumberTitle','off');
mu = [0 ;0];
covariance = [0.5 0.8; 0.8 2.0];
x1 = -3:0.2:3;
x2 = -3:0.2:3;
x = [x1; x2];
[X1,X2] = meshgrid(x1,x2);
Z = 1/(2*pi*(det(covariance))^(-0.5))* exp(-(1/2).*(x-mu)'*pinv(covariance)*(x-mu));
Z = reshape(Z,size(X1));
surf(X1,X2,Z)
xlabel('x')
ylabel('y')
zlabel('Bivariate Gaussian Distributions')
Output:

Why are the outputs from the two methods different? How can I get the correct output for a bivariate gaussian distribution by the 2nd method? Please help
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!