您好,欢迎访问三七文档
概率论实验实验报告2015年6月11n个人中至少有两人生日相同的概率是多少?通过计算机模拟此结果。程序:n=[1,2,10,100];N=10000;M=zeros(1,length(n));fork=1:length(n)fori=1:NX=ceil(365*rand(1,n(k)));Y=unique(X);iflength(Y)n(k)M(k)=M(k)+1;endendendp=M/N运行结果:p=00.00220.11811.0000p=00.00330.11291.0000p=00.00220.11631.0000p=00.00260.11511.0000实验结论:当人数为1时,至少两人同一天生日概率模拟值接近0当人数为2时,至少两人同一天生日概率模拟值接近0.0027当人数为10时,至少两人同一天生日概率模拟值接近0.1156当人数为100时,至少两人同一天生日概率模拟值接近12设X~),(2N;(1)当5.0,5.1时,求}9.28.1{XP,2}5.2{XP,}6.1|7.1{|XP;(1)当5.0,5.1时,若95.0}{xXP,求x;(2)分别绘制3,2,1,5.0时的概率密度函数图形。程序:clearclcmu=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.2717p2=1.0000p3=30.0027x=2.3224结论:当5.0,5.1时{1.82.9}0.2717PX{2.5}1PX{|1.7|1.6}0.0027PX若95.0}{xXP,求2.3224x;3已知每百份报纸全部卖出可获利14元,卖不出去将赔8元,设报纸的需求量X的分布律为X012345-1-0.500.511.522.5300.51=100.511.522.533.5400.51=211.522.533.544.5500.51=34P0.050.100.250.350.150.10试确定报纸的最佳购进量n。(要求使用计算机模拟)理论值:程序:P=[0.050.100.250.350.150.10];X=0:5;Profit=zeros(1,6);forx=1:6fori=1:x-1Profit(x)=Profit(x)+22*X(i)*P(i);endfori=x:6Profit(x)=Profit(x)+22*(x-1)*P(i);endProfit(x)=Profit(x)-8*(x-1);endstem(X,Profit)Profit运行结果:Profit=012.900023.600028.800026.300020.50005模拟值:程序:N=[10,100,1000,10000];fork=1:4need=rand(1,N(k));fori=1:N(k)ifneed(i)=0&&need(i)0.05need(i)=0;elseifneed(i)=0.05&&need(i)0.15need(i)=1;elseifneed(i)=0.15&&need(i)0.4need(i)=2;elseifneed(i)=0.4&&need(i)0.75need(i)=3;elseifneed(i)=0.75&&need(i)0.9need(i)=4;elseifneed(i)=0.9&&need(i)=1need(i)=5;endendforx=0:5sale=-8*x*ones(1,N(k));fori=1:N(k)ifneed(i)=x00.511.522.533.544.550510152025306sale(i)=sale(i)+22*x;elsesale(i)=sale(i)+22*need(i);endendProfit(x+1)=mean(sale);endstem(0:5,Profit)Profitend运行结果:Profit=014.000025.800031.000025.200017.2000Profit=012.680023.160028.580024.980018.9600Profit=013.032023.644028.822026.344020.5880Profit=012.816423.582428.797826.286820.5154结论:重复试验次数01百份2百份3百份4百份5百份10次01425.83125.217.2100次012.6823.1628.5824.9818.961000次013.03223.64428.82226.34420.58810000次012.816423.582428.797826.286820.5154理论值012.923.628.826.320.5随重复试验的次数增多,模拟值逐渐接近理论值。观察发现,当购进量为3百份时,利润期望值最高。4.设总体]1,0[~X,),,,(21nXXX是来自总体X的一组样本,通过7计算机模拟分别画出当,20,10,4,2n时niiX1的概率密度曲线,观察当n越来越大时的概率密度曲线是否与某正态分布的概率密度曲线接近,以此验证中心极限定理。程序:clearn=[2,4,10,20,100,1000];m=50000;fork=1:length(n)figuretemp=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);holdonplot(x,p,'b',xx,yy,'r--')legend(['n='num2str(n(k))],['N~('num2str(mu)','num2str(sigma)')'])title(['n='num2str(n(k))])end8-1-0.500.511.522.5300.10.20.30.40.50.60.70.80.91n=2n=2N~(1,0.40825)-0.500.511.522.533.544.500.10.20.30.40.50.60.7n=4n=4N~(2,0.57735)9012345678900.050.10.150.20.250.30.350.40.45n=10n=10N~(5,0.91287)4681012141600.050.10.150.20.250.30.35n=20n=20N~(10,1.291)105.就不同的自由度画出2分布、t分布及F分布的概率密度曲线,每种情况至少画三条曲线,并将t分布的概率密度曲线与3540455055606500.020.040.060.080.10.120.14n=100n=100N~(50,2.8868)45046047048049050051052053054055000.0050.010.0150.020.0250.030.0350.040.045n=1000n=1000N~(500,9.1287)11标准正态分布的概率密度曲线进行比较。程序:figurex=0:.01:5;y=pdf('chi2',x,1);plot(x,y,'b')holdony=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')figurex=-5:.01:5;y=pdf('t',x,1);plot(x,y,'b')holdony=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)')figurex=0:.01:5;y=pdf('f',x,10,1000000000000);plot(x,y,'b')holdony=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')运行结果:12n=1000000000000时,基本与标准正态重合。00.511.522.533.544.5500.511.522.533.542n=1n=2n=3-5-4-3-2-101234500.050.10.150.20.250.30.350.4tn=1n=2n=1000000000000N(0,1)136就正态总体的某一个参数,构造置信区间,以检验置信度。即通过随机产生100组数据,构造100个置信区间,观察是否有100(1-)%个区间包含此参数。程序:clearm=100;mu=1.5;sigma=3;alpha=[0.10.050.01];count(3)=0;fork=1:3fori=1:100X=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&&UPmucount(k)=count(k)+1;endendendp=count/10000.511.522.533.544.5500.10.20.30.40.50.60.70.80.91Fm=10,n=1000000000000m=10,n=10m=10,n=414运行结果:p=0.91000.96000.9800p=0.92000.93000.9900p=0.88000.94001.0000p=0.91000.92000.9900结论:对参数mu构造置信区间;当alpha=0.1时,包含mu的区间的概率接近0.9当alpha=0.05时,包含mu的区间的概率接近0.95当alpaca=0.01时,包含mu的区间的概率接近0.997.对于正态总体,当均值已知时,至少用两种方法构造方差的置信度为95%的置信区间,比较两种方法的优劣。验证所构造的置信区间置信度为95%程序:a=1;b=0.5;n=100;alpha=0.05;count1=0;count2=0;fori=1:100X=a+b*randn(1,n);%X~N(a,b)UP1=sum((X-a).^2)/(chi2inv(alpha/2,n));15DOWN1=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
本文标题:概率论实验
链接地址:https://www.777doc.com/doc-2302972 .html