你好,考试题,请自己回答,这样更能学习进步哦
% 【5】(20分,概率论)
% 对正态分布的3a法则进行演示,设x~N(.²)=N(4.4)。
miu = 4;
sigma = 4;
%(1)画出其密度函数曲线f(x);
figure(1);
x = -46:0.01:54;
y = fx(x, miu, sigma^2); % 自写函数
plot(x,y,'-b');
hold on;
%(2)分别对(u-a,+a),(-2a,u+2a),(u-30,+3a)进行填充;
figure(2);
subplot(1,3,1);
%x = miu-sigma:0.01: miu+sigma;
x = -46:0.01:54;
y = fx(x, miu, sigma^2); % 自写函数
plot(x,y,'-b');
hold on;
h=fill(x,y,'b');
set(h,'edgealpha',0,'facealpha',0.3);
grid on;
xlabel('(\mu-\sigma ,\mu+\sigma)');
subplot(1,3,2);
%x_per=miu-2*sigma:0.01:miu+2*sigma;
x = -46:0.01:54;
y_per = fx(x_per, miu, sigma^2); % 自写函数
plot(x_per,y_per,'-b');
hold on;
h2=fill(x_per,y_per,'r');
set(h2,'edgealpha',0,'facealpha',0.3);
grid on;
xlabel('(\mu-2\sigma ,\mu+2\sigma)');
%画出这N个二维随机数(x.y)的散点图。
subplot(1,3,3);
%x_per=miu-3*sigma:0.01:miu+3*sigma;
x = -46:0.01:54;
y_per = fx(x_per, miu, sigma^2); % 自写函数
plot(x_per,y_per,'-b');
hold on;
h2=fill(x_per,y_per,'g');
set(h2,'edgealpha',0,'facealpha',0.3);
grid on;
xlabel('(\mu-3\sigma ,\mu+3\sigma)');
%(3)先产生N-1000个随机数x-N(),在x=x的条件下,再产生与x对应的N个随机数
miu1 =0;
miu2=0;
sigma1=1;
sigma2=2;
rou=0.6;
X=normrnd(miu1,sigma1.^2,1000,1);
Y=normrnd(miu2+(X-miu1)/sigma1*sigma2*rou, sigma2^2*(1-rou^2));
figure(3);
plot(X,Y,'.');
%(4)画出随机变量的密度函数曲线和随机数x的频率点图
figure(4);
hist(X);
%(5)画出随机变量的密度函数曲线和随机数y的频率点图。
figure(5);
hist(Y);
fx函数:
% 概率密度函数
function f = fx(x, miu, sig)
f = (sqrt(2*pi)*sig).^(-1) * exp(-(x-miu).^2/(2*sig*sig));