资源描述:
《随机matlab程序2》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、随机作业学号:S307040113姓名:叶增本次作业是在MATLAB7.0环境下写出。第一题:用PC机产生[0,1]均匀分布的白色序列(1)打印出前50个数(2)分布检验(3)均值检验(4)方差检验(5)相关检验源程序:x=rand(1,2000);%产生[0,1]的均匀分布白色序列fori=1:50y(i)=x(i);enddisp(y)%显示前50个数subplot(2,1,1);%分布检验hist(x,10);%画直方图%求均值检验EX1=mean(x)%方差检验DX1=var(x)%相关函数sum3=0;EX=0.5;form=-10:10for
2、n=1:(2000-abs(m))sum3=sum3+((x(1,n+abs(m))-EX)*(x(1,n)-EX));endBx(1,m+11)=sum3/2000;sum3=0;endm=-10:10;subplot(2,1,2);plot(m,Bx)(1)打印出前50个数160.82140.73630.98060.82440.67010.98730.54820.91140.66210.83970.20240.80350.71730.76250.10480.65520.44600.55920.33390.32870.00050.03830.78050
3、.01370.43260.61670.49020.07800.55160.06080.93340.55480.19050.29390.96870.82850.90860.89670.73790.07350.71790.70350.60630.32360.75930.78450.13270.81700.57280.1607(2)分布检验图(3)均值检验EX=0.5067;(4)方差检验DX=0.0851;(5)相关函数图第二题:用PC机产生分布的正态序列(1)打印出前50个数(2)分布检验(3)均值检验(4)方差检验(5)相关检验16源程序:x2=rand
4、n(1,2000);%产生[0,1]的正态分布随机矩阵subplot(2,1,1);%分布检验hist(x2,18);%画直方图fbsum1=zeros(1,18);%求取实际值fori=1:2000forj=1:18if(x2(i)>=(-3+(j-1)/3)&x2(i)<(-3+j/3))fbsum1(j)=fbsum1(j)+1;endendendfbsum2=zeros(1,18);%用积分求取理论值fori=1:18fbsum2(i)=(quad('ztfb',(-3+(i-1)/3),(-3+i/3)));%求积分fbsum2(i)=fbsu
5、m2(i)*2000;end%求均值检验EX2=mean(x2)%方差检验DX2=var(x2)%相关函数sum=0;EX=0;form=-20:20forn=1:(2000-abs(m))sum=sum+((x2(1,n+abs(m))-EX)*(x2(1,n)-EX));endBx2(1,m+21)=sum/2000;sum=0;endm=-20:20;subplot(2,1,2);plot(m,Bx2)%其中ztfb函数为16functiony=ztfb(x)%标准正态分布函数y=exp((-x.^2)/2)/sqrt(2*pi);(1)打印出前5
6、0个数-1.0457-1.0045-0.7384-0.9445-0.1354-0.42261.5979-0.38110.2348-0.30930.34090.5486-1.0160-1.6335-1.8104-0.03490.6758-0.8909-1.89132.2175-0.9381-1.54360.1596-0.3688-1.01220.11340.8850-0.5823-0.7176-0.6733-0.31971.60651.06130.30050.35110.9522-0.6329-0.85871.7461-0.5561-0.02430.917
7、0-0.5015-0.25131.6728-1.3644-0.33511.29460.4811-0.2520(2)分布检验-3--2.6667-2.6667--2.3333-2.3333--2-2--1.6666-1.6666--1.3333-1.3333--1理论值4.961011.969925.869650.080486.8417134.8881实际值416205686128-1--0.6666-0.6666--0.3333-0.3333-00-0.33330.3333-0.66660.6666-1理论值187.6746233.8976261.117
8、3261.1173233.8976187.6746实际值186244279261