%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%本程序用于产生一维正态分布、二维正态分布
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%绘制一维正态分布
x=linspace(-3,3);
y=normpdf(x,0,1);
figure(1)
plot(x,y,'r');
%绘制二维正态分布
x=-20:0.5:20;
y=-20:0.5:20;
mu=[-1,2];
sigma=[1 1; 1 3]; % 输入均值向量和协方差矩阵,可以根据需要修改
[X,Y]=meshgrid(x,y); % 产生网格数据并处理
p=mvnpdf([X(:),Y(:)],mu,sigma);
P=reshape(p,size(X)); % 求取联合概率密度
figure(2)
surf(X,Y,P)
shading interp
colorbar
title('条件概率密度函数曲线');
结果显示:
一维正态分布:
二维正态分布: