多元法线密度的表面图

时间:2018-11-27 23:14:26

标签: matlab normal-distribution probability-density

我有一个Multivariate Normal Density的似然函数,其均值为mu=[3 5]'covariance=9*I。如何在Matlab中绘制其2D曲面?

2 个答案:

答案 0 :(得分:0)

对数似然函数可以从PDF或通过引用wiki获得。

Mu = [3 5]';
Sigma = 9*eye(2);
loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi);  % For single x

xMin = -2;
xMax = 7;
step = 0.1;
X1 = xMin:step:xMax;
X2 = xMin:step:xMax;
L = zeros(length(X1),length(X2));
for i = 1:length(X1)
    for j = 1:length(X2)
       x = [X1(i) X2(j)]';
       L(i,j) = loglikeh(x);
    end
end

如果我犯了一个错误,请发表评论以便我修复。希望这可以帮助。

绘图

surf(X1,X2,L')      % Note L is transposed if done this way
xlabel('x_1')
ylabel('x_2')
zlabel('log-likelihood')

有关更多的可视化效果和选项,请参见these answers

答案 1 :(得分:-1)

您可以尝试在此处引用: (在MATLAB中使用mvnpdf函数) F = mvnpdf([X1(:) X2(:)],mu,Sigma) 请在这里https://www.mathworks.com/help/stats/multivariate-normal-distribution.html

检查