概率论实验.docx

上传人:b****8 文档编号:10931465 上传时间:2023-02-23 格式:DOCX 页数:22 大小:122.20KB
下载 相关 举报
概率论实验.docx_第1页
第1页 / 共22页
概率论实验.docx_第2页
第2页 / 共22页
概率论实验.docx_第3页
第3页 / 共22页
概率论实验.docx_第4页
第4页 / 共22页
概率论实验.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

概率论实验.docx

《概率论实验.docx》由会员分享,可在线阅读,更多相关《概率论实验.docx(22页珍藏版)》请在冰豆网上搜索。

概率论实验.docx

概率论实验

概率论实验

 

2015年6月

1

个人中至少有两人生日相同的概率是多少?

通过计算机模拟此结果。

程序:

n=[1,2,10,100];

N=10000;

M=zeros(1,length(n));

fork=1:

length(n)

fori=1:

N

X=ceil(365*rand(1,n(k)));

Y=unique(X);

iflength(Y)

M(k)=M(k)+1;

end

end

end

p=M/N

运行结果:

p=

00.00220.11811.0000

p=

00.00330.11291.0000

p=

00.00220.11631.0000

p=

00.00260.11511.0000

实验结论:

当人数为1时,至少两人同一天生日概率模拟值接近0

当人数为2时,至少两人同一天生日概率模拟值接近0.0027

当人数为10时,至少两人同一天生日概率模拟值接近0.1156

当人数为100时,至少两人同一天生日概率模拟值接近1

2设

(1)当

时,求

;

(1)当

时,若

,求

(2)分别绘制

时的概率密度函数图形。

程序:

clear

clc

mu=1.5;

sigma=0.5;

p1=normcdf(2.9,mu,sigma)-normcdf(1.8,mu,sigma)

p2=1-normcdf(-2.5,mu,sigma)

p3=normcdf(0.1,mu,sigma)+(1-normcdf(3.3,mu,sigma))

x=norminv(0.95,mu,sigma)

fx=-2:

.1:

2;

f1=pdf('norm',fx+1,1,0.5);

subplot(311)

plot(fx+1,f1)

title('\mu=1')

f1=pdf('norm',fx+2,2,0.5);

subplot(312)

plot(fx+2,f1)

title('\mu=2')

f1=pdf('norm',fx+3,3,0.5);

subplot(313)

plot(fx+3,f1)

title('\mu=3')

运行结果:

p1=

0.2717

 

p2=

1.0000

 

p3=

0.0027

 

x=

2.3224

结论:

,求

3已知每百份报纸全部卖出可获利14元,卖不出去将赔8元,设报纸的需求量

的分布律为

012345

0.050.100.250.350.150.10

试确定报纸的最佳购进量

(要求使用计算机模拟)

理论值:

程序:

P=[0.050.100.250.350.150.10];

X=0:

5;

Profit=zeros(1,6);

forx=1:

6

fori=1:

x-1

Profit(x)=Profit(x)+22*X(i)*P(i);

end

fori=x:

6

Profit(x)=Profit(x)+22*(x-1)*P(i);

end

Profit(x)=Profit(x)-8*(x-1);

end

stem(X,Profit)

Profit

 

运行结果:

Profit=

012.900023.600028.800026.300020.5000

模拟值:

程序:

N=[10,100,1000,10000];

fork=1:

4

need=rand(1,N(k));

fori=1:

N(k)

ifneed(i)>=0&&need(i)<0.05

need(i)=0;

elseifneed(i)>=0.05&&need(i)<0.15

need(i)=1;

elseifneed(i)>=0.15&&need(i)<0.4

need(i)=2;

elseifneed(i)>=0.4&&need(i)<0.75

need(i)=3;

elseifneed(i)>=0.75&&need(i)<0.9

need(i)=4;

elseifneed(i)>=0.9&&need(i)<=1

need(i)=5;

end

end

forx=0:

5

sale=-8*x*ones(1,N(k));

fori=1:

N(k)

ifneed(i)>=x

sale(i)=sale(i)+22*x;

else

sale(i)=sale(i)+22*need(i);

end

end

Profit(x+1)=mean(sale);

end

stem(0:

5,Profit)

Profit

end

运行结果:

Profit=

014.000025.800031.000025.200017.2000

 

Profit=

012.680023.160028.580024.980018.9600

 

Profit=

013.032023.644028.822026.344020.5880

 

Profit=

012.816423.582428.797826.286820.5154

 

结论:

重复试验次数

0

1百份

2百份

3百份

4百份

5百份

10次

0

14

25.8

31

25.2

17.2

100次

0

12.68

23.16

28.58

24.98

18.96

1000次

0

13.032

23.644

28.822

26.344

20.588

10000次

0

12.8164

23.5824

28.7978

26.2868

20.5154

理论值

0

12.9

23.6

28.8

26.3

20.5

随重复试验的次数增多,模拟值逐渐接近理论值。

观察发现,当购进量为3百份时,利润期望值最高。

4.设总体

是来自总体

的一组样本,通过计算机模拟分别画出当

的概率密度曲线,观察当

越来越大时的概率密度曲线是否与某正态分布的概率密度曲线接近,以此验证中心极限定理。

程序:

clear

n=[2,4,10,20,100,1000];

m=50000;

fork=1:

length(n)

figure

temp=rand(n(k),m);

One=ones(1,n(k));

X=One*temp;

[p,x]=ksdensity(X);

mu=0.5*n(k);

sigma=sqrt(n(k)/(12));

xx=mu-4*sigma:

.1:

mu+4*sigma;

yy=pdf('norm',xx,mu,sigma);

holdon

plot(x,p,'b',xx,yy,'r--')

legend(['n='num2str(n(k))],['N~('num2str(mu)','num2str(sigma)')'])

title(['n='num2str(n(k))])

end

5.就不同的自由度画出

分布、

分布及F分布的概率密度曲线,每种情况至少画三条曲线,并将

分布的概率密度曲线与标准正态分布的概率密度曲线进行比较。

程序:

figure

x=0:

.01:

5;

y=pdf('chi2',x,1);

plot(x,y,'b')

holdon

y=pdf('chi2',x,2);

plot(x,y,'r')

y=pdf('chi2',x,3);

plot(x,y,'g')

title('\chi^2')

legend('n=1','n=2','n=3')

figure

x=-5:

.01:

5;

y=pdf('t',x,1);

plot(x,y,'b')

holdon

y=pdf('t',x,2);

plot(x,y,'c')

y=pdf('t',x,1000000000000);

plot(x,y,'g')

y=pdf('norm',x,0,1);

plot(x,y,'r--')

title('t')

legend('n=1','n=2','n=1000000000000','N(0,1)')

figure

x=0:

.01:

5;

y=pdf('f',x,10,1000000000000);

plot(x,y,'b')

holdon

y=pdf('f',x,10,10);

plot(x,y,'r')

y=pdf('f',x,10,4);

plot(x,y,'g')

title('F')

legend('m=10,n=1000000000000','m=10,n=10','m=10,n=4')

运行结果:

n=1000000000000时,基本与标准正态重合。

6就正态总体的某一个参数,构造置信区间,以检验置信度。

即通过随机产生100组数据,构造100个置信区间,观察是否有100(1-

)%个区间包含此参数。

程序:

clear

m=100;

mu=1.5;

sigma=3;

alpha=[0.10.050.01];

count(3)=0;

fork=1:

3

fori=1:

100

X=mu+sigma*randn(1,m);%X~N(mu,sigma)

UP=mean(X)+norminv(1-alpha(k)/2,0,1)*sigma/sqrt(m);

DOWN=mean(X)-norminv(1-alpha(k)/2,0,1)*sigma/sqrt(m);

ifDOWNmu

count(k)=count(k)+1;

end

end

end

p=count/100

运行结果:

p=

0.91000.96000.9800

 

p=

0.92000.93000.9900

 

p=

0.88000.94001.0000

 

p=

0.91000.92000.9900

结论:

对参数mu构造置信区间;

当alpha=0.1时,包含mu的区间的概率接近0.9

当alpha=0.05时,包含mu的区间的概率接近0.95

当alpaca=0.01时,包含mu的区间的概率接近0.99

7.对于正态总体,当均值已知时,至少用两种方法构造方差的置信度为95%的置信区间,比较两种方法的优劣。

验证所构造的置信区间置信度为95%

程序:

a=1;

b=0.5;

n=100;

alpha=0.05;

count1=0;

count2=0;

fori=1:

100

X=a+b*randn(1,n);%X~N(a,b)

UP1=sum((X-a).^2)/(chi2inv(alpha/2,n));

DOWN1=sum((X-a).^2)/(chi2inv(1-alpha/2,n));

UP2=n*(mean(X)-a)^2/(chi2inv(alpha/2,1));

DOWN2=n*(mean(X)-a)^2/(chi2inv(1-alpha/2,1));

ifDOWN1

count1=count1+1;

end

ifDOWN2

count2=count2+1;

end

end

count1/100

count2/100

运行结果:

method1=

0.9300

 

method2=

0.9500

 

method1=

0.9500

 

method2=

0.9200

 

method1=

0.9600

 

method2=

0.9600

所构造的区间满足置信度95%

构造

UP1=

0.3248

 

DOWN1=

0.1861

 

UP1=

0.3482

 

DOWN1=

0.1994

 

UP1=

0.4066

 

DOWN1=

0.2329

构造

UP2=

222.0616

 

DOWN2=

0.0434

 

UP2=

1.9079

 

DOWN2=

3.7295e-004

 

UP2=

68.4270

 

DOWN2=

0.0134

结论:

构造

构造

第一次

(0.1861,0.3248)

(0.0434,222.0616)

第二次

(0.1994,0.3482)

(3.7295e-004,1.9079)

第三次

(0.2329,0.4066)

(0.0134,68.4270)

……

……

……

构造的区间比用

构造的区间长度要长,效果要差。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1