作业一1.用matlab编写样本均值和方差的程序X=input('请输入样本值:\n');%以矩阵形式输入%a=mean(X)%求均值%b=var(X)%求方差%2.编写均值差的置信区间程序%两正态总体方差未知,但方差相等%X=input('请输入正态总体X的样本值:\n');Y=input('请输入正态总体Y的样本值:\n');S1=var(X);%求样本X的方差%S2=var(Y);%求样本Y的方差%n11=size(X);n22=size(Y);n1=n11(:,2);n2=n22(:,2);%计算样本X,Y的个数%Sw=sqrt(((n1-1)*S1+(n2-1)*S2)/(n1+n2-2));%求Sw%a=mean(X);%求样本X的均值%b=mean(Y);%求样本Y的均值%L=input('请输入置信度:\n');alpha=1-L;t=tinv(1-alpha/2,n1+n2-2);%置信度为L的T值%d1=(a-b)-t*Sw.*sqrt(1./n1+1./n2);%置信区间下界%d2=(a-b)+t*Sw.*sqrt(1./n1+1./n2);%置信区间上界%c=[d1,d2]%均值差置信区间%%两正态总体方差已知,为sigma1,sigma2%X=input('请输入正态总体X的样本值:\n');Y=input('请输入正态总体Y的样本值:\n');a=mean(X);%求样本X的均值%b=mean(Y);%求样本Y的均值%n11=size(X);n22=size(Y);n1=n11(:,2);n2=n22(:,2);%计算样本X,Y的个数%L=input('请输入置信度:\n');alpha=1-L;u=norminv(1-alpha/2);%置信区间为1-alpha的U值%sigma1=input('请输入总体X的方差平方根:\n');sigma2=input('请输入总体Y的方差平方根:\n');d1=a-b-u*sqrt(sigma1.^2/n1+sigma2.^2/n2);%置信区间下界%d2=a-b+u*sqrt(sigma1.^2/n1+sigma2.^2/n2);%置信区间上界%c=[d1,d2]%均值差置信区间%3.编写两样本T检验程序%两样本t检验法,总体方差未知但相等%X=input('请输入正态总体X的样本值:\n');Y=input('请输入正态总体Y的样本值:\n');S1=var(X);%求样本X的方差%S2=var(Y);%求样本Y的方差%n11=size(X);n22=size(Y);n1=n11(:,2);n2=n22(:,2);%计算样本X,Y的个数%Sw=sqrt(((n1-1)*S1+(n2-1)*S2)/(n1+n2-2));%求Sw%a=mean(X);%求样本X的均值%b=mean(Y);%求样本Y的均值%L=input('请输入置信度:\n');alpha=1-L;t=tinv(1-alpha/2,n1+n2-2);%置信度为L的T值%%%if(abs(a-b)Sw.*t*sqrt(1/n1+1/n2))%双侧检验,u1=u2%%%if((a-b)Sw.*t*sqrt(1/n1+1/n2))%单侧检验,u1-u2=0%%%if((a-b)-(Sw.*t*sqrt(1/n1+1/n2)))%单侧检验,u1-u2=0%disp('拒绝假设')elsedisp('假设成立')end4.证明样本方差是总体方差的无偏估计量(详见概率课本P159)