概率论实验 02 - | 基于Matlab随机数的产生和特性统计

该实验旨在通过MATLAB编程生成不同分布的随机数,包括均匀分布和正态分布,并通过统计分析验证其概率特性。实验内容包括绘制随机数分布图、计算均值与方差、建立直方图以及对比理论概率密度函数。通过实验,学生能够理解并掌握随机数生成方法及其概率特性验证过程。
摘要由CSDN通过智能技术生成

一、实验目的

1.了解随机数的产生方法; 

2.了解随机数的概率特性; 

3.产生实际随机数进行验证。

二、实验原理

随机数的产生有好多方法,可以利用乘积法和同余法产生[0,1]之间的均匀分布,然后利用函数变换法产生所需不同分布的随机数。可以按照所产生的随机数,对落在不同区间的数据进行统计,从而画出所产生随机数的统计特性。所有这些工作我们可以自己动手用MATLAB,VC或VB等语言进行编程实现。

三、实验内容与步骤

1.

close all
clear all
n=5000;
m=100;
xmin=0,xmax=1;
x=rand(1,n);
subplot(3,1,1);
plot(x,'.');
cc=sprintf('Uniform Distribution,n=%d',n);
title(cc);
subplot(3,1,2);
m1=mean(x);
c2=var(x);
x1=xmin:(xmax-xmin)/m:xmax;
h=hist(x,x1);
bar(x1,h);
grid on
cc=sprintf('Uniform Distribution Histogram n=%d',n);
title(cc);
cc=sprintf('mean=%5.2f',m1);
gtext(cc);
cc=sprintf('C^2=%5.3f',c2);
gtext(cc);
subplot(3,1,3);
pdf1=h/n/((xmax-xmin)/m);
plot(x1,pdf1);
grid on

2.

close all
clear all
n=5000;
m=100;
xmin=-5,xmax=5;
x=randn(1,n);
subplot(3,1,1);
plot(x,'.');
cc=sprintf('Uniform Distribution,n=%d',n);
title(cc);
subplot(3,1,2);
m1=mean(x);
c2=var(x);
x1=xmin:(xmax-xmin)/m:xmax;
h=hist(x,x1);
bar(x1,h);
grid on
cc=sprintf('Uniform Distribution Histogram n=%d',n);
title(cc);
cc=sprintf('mean=%5.2f',m1);
gtext(cc);
cc=sprintf('C^2=%5.3f',c2);
gtext(cc);
subplot(3,1,3);
pdf1=h/n/((xmax-xmin)/m);
plot(x1,pdf1);
grid on

3.

close all
clear all
n=5000;
m=100;
xmin=-5,xmax=5;
x=rand(12,n);
x=sum(x)-6;
subplot(3,1,1);
plot(x,'.');
cc=sprintf('Uniform Distribution,n=%d',n);
title(cc);
subplot(3,1,2);
m1=mean(x);
c2=var(x);
x1=xmin:(xmax-xmin)/m:xmax;
h=hist(x,x1);
bar(x1,h);
grid on
cc=sprintf('Uniform Distribution Histogram n=%d',n);
title(cc);
cc=sprintf('mean=%5.2f',m1);
gtext(cc);
cc=sprintf('C^2=%5.3f',c2);
gtext(cc);
subplot(3,1,3);
pdf1=h/n/((xmax-xmin)/m);
plot(x1,pdf1);
grid on

4.

close all
clear all
n=5000;
m=100;
xmin=-5,xmax=5;
u1=rand(1,n);
u2=rand(1,n)
x=sqrt(-log(u1)).*cos(2*pi*u2);
subplot(3,1,1);
plot(x,'.');
cc=sprintf('Uniform Distribution,n=%d',n);
title(cc);
subplot(3,1,2);
m1=mean(x);
c2=var(x);
x1=xmin:(xmax-xmin)/m:xmax;
h=hist(x,x1);
bar(x1,h);
grid on
cc=sprintf('Uniform Distribution Histogram n=%d',n);
title(cc);
cc=sprintf('mean=%5.2f',m1);
gtext(cc);
cc=sprintf('C^2=%5.3f',c2);
gtext(cc);
subplot(3,1,3);
pdf1=h/n/((xmax-xmin)/m);
plot(x1,pdf1);
grid on

5.

close all
clear all
n=5000;
m=100;
xmin=-3,xmax=8;
y=randn(1,n);
x=y*1+2;
subplot(3,1,1);
plot(x,'.');
cc=sprintf('Uniform Distribution,n=%d',n);
title(cc);
subplot(3,1,2);
m1=mean(x);
c2=var(x);
x1=xmin:(xmax-xmin)/m:xmax;
h=hist(x,x1);
bar(x1,h);
grid on
cc=sprintf('Uniform Distribution Histogram n=%d',n);
title(cc);
cc=sprintf('mean=%5.2f',m1);
gtext(cc);
cc=sprintf('C^2=%5.3f',c2);
gtext(cc);
subplot(3,1,3);
pdf1=h/n/((xmax-xmin)/m);
plot(x1,pdf1);
grid on

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式逍遥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值