X~2分布、t分布和f分布地性质及近似计算_第1页
X~2分布、t分布和f分布地性质及近似计算_第2页
X~2分布、t分布和f分布地性质及近似计算_第3页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、以下为三个分布的动画演示程序,直接运行:functiondandn(action)%«X2分布、t分布和f分布的性质及近似计算%制作人:幸玮石岩顾秋容%AllRightsReserved%2008.12%无输入参数时进行初始程序,否则调界面参数ifnargin<1,action='initialize'else%看是哪种分布data=get(gco,'UserData');pdflabel=data(4);%图形显示参数,调试时用switchpdflabelcase1xstart=0;%x轴起始点width=120;%x轴范围xdis=30;%x

2、轴刻度间距lenth=0.24;%y轴范围ydis=0.03;%y轴刻度间距speed=0.6;%动画演进速率case2width=6;xdis=3;lenth=0.42;ydis=0.05;speed=0.5;case3width=2;xdis=0.5;lenth=4;ydis=0.4;speed=0.8;endend%初始化模块ifstrcmp(action,'initialize')%数据初始化%分布函数选择pdflabel=0;d=inputdlg('输入分布函数类型:','选择分布函数,1,'x2');ifstrcmp(d,&#

3、39;x2')pdflabel=1;elseifstrcmp(d,'t')pdflabel=2;elseifstrcmp(d,'f')pdflabel=3;end%不符合的输入报错ifpdflabel=0errordlg('分布函数只能选择x2,t与f)returnend%整体用户界面建立,图形显示窗口嵌入figNumber=figure(.'Name','ChangingoftheX2destributionfunction''NumberTitle','off',.'Vi

4、sible','off);axes(.'Units','normalized',.'Visible','off,.'Position',0.060.0650.700.9);%显示初始现实画面switchpdflabelcase1%初始显示参数xstart=0;%x轴起始点width=120;%x轴范围xdis=30;%x轴刻度间距lenth=0.24;%y轴范围ydis=0.03;%y轴刻度间距%画背景图plot(xstartxstart+width,lenthlenth,'b');hold

5、onplot(xstartxstart+width,lenthlenth,'r');plot(xstartxstart+width,lenthlenth,'black');legend('X2分布','正态分布');axis(xstartxstart+width0lenth);gridonset(gca,'XTick',xstart:xdis:xstart+width);set(gca,'YTick',0:ydis:lenth);holdoff%分布函数动画初始参数m=0;n=1;case2widt

6、h=6;xdis=3;lenth=0.42;ydis=0.05;plot(-width-widthwidth,0lenthlenth,'b');holdonplot(-width-widthwidth,0lenthlenth,'r-');plot(-width-widthwidth,0lenthlenth,'black');legend('T分布','正态分布');gridonaxis(-widthwidth0lenth);set(gca,'XTick',-width:xdis:width);set

7、(gca,'YTick',0:ydis:lenth);holdoffm=0;n=2;otherwisewidth=2;xdis=0.5;lenth=4;ydis=0.4;plot(width,0,'b');holdonplot(width,0,'r');legend('f分布','正态分布');axis(0width0lenth);gridonset(gca,'XTick',0:xdis:width);set(gca,'YTick',0:ydis:lenth);holdoff%f分布

8、输入nn=inputdlg('输入n的值:','获取n',1,'5');n=str2double(n1);ifn<=4errordlg('要使正态逼近式成立n必须大于4!')returnendm=1;end%按钮显示位置top=0.95;left=0.80;btnWid=0.15;btnHt=0.08;spacing=0.02;%“Start”按钮btnNumber=1;labelStr='Start'callbackStr='dandn(''start'')'

9、%显示按钮btnPos=lefttop-btnHtbtnWidbtnHt;uicontrol(.'Style','pushbutton',.'Units','normalized',.'Position',btnPos,.'String',labelStr,.'Callback',callbackStr,.'UserData',btnNumbermnpdflabel);%调用时的句柄参数传递%关闭按钮yPos=top-(btnHt+spacing);uicontrol

10、(.'Style','push',.'Units','normalized',.'Position',leftyPos-btnHtbtnWidbtnHt,.'String','Close',.'Callback','close(gcf)');set(figNumber,'Visible','on');%显示初始图像%“Start”按钮执行程序elseifstrcmp(action,'start')%参数初

11、始化data=get(gco,'UserData');method=data(1);m=data(2);n=data(3);%“Stop”按钮设置,点击开始后替换“Start”按钮btnNumber=2;labelStr='Stop'callbackStr='dandn(''stop'')'top=0.95;left=0.80;btnWid=0.15;btnHt=0.08;btnPos=lefttop-btnHtbtnWidbtnHt;stophld=uicontrol(.'Style','

12、pushbutton',.'Units','normalized',.'Position',btnPos,.'String',labelStr,.'Callback',callbackStr,.'UserData',btnNumbermnpdflabel);%画图程序switchpdflabelcase1while(method=1)%当未点击"Stop”则继续执行%画x2分布密度函数a=n/2;b=2;x=xstart:0.1:xstart+width;y=gampdf(x,a,

13、b);plot(x,y,'b','EraseMode','normal');holdon%画近似正太分布密度函数y1=normpdf(x,n,(2*n)A0.5);plot(x,y1,'r-');%图形参数调节axis(xstartxstart+width0lenth);set(gca,'XTick',xstart:xdis:xstart+width);set(gca,'YTick',0:ydis:lenth);gridon;legend('X2分布','正态分布')

14、;%显示当前ntemp=num2str(floor(n);str=strcat('n=',temp);text(92,0.2,str);%显示当前最大间距dis=num2str(max(abs(y-y1);str=strcat('dis=',dis);text(92,0.187,str);%动画指令drawnow;holdoff;n=n+speed;%看stop是否按下data=get(gco,'UserData');method=data(1);%更新传递参数set(stophld,'Userdata',btnNumbermnp

15、dflabel);endcase2while(method=1)%画t分布密度函数x=-width:0.1:width;y=tpdf(x,n);plot(x,y,'EraseMode','normal');holdon%画近似正太分布密度函数y1=normpdf(x,0,(n/(n-2)A0.5);plot(x,y1,'r-');%图形参数调节axis(-widthwidth0lenth);set(gca,'XTick',-width:xdis:width);set(gca,'YTick',0:ydis:lenth

16、);gridon;legend('T分布','正态分布');%显示当前ntemp=num2str(floor(n);z=strcat('n=',temp);text(3.3,0.335,z);%显示当前最大间距dis=num2str(max(abs(y-y1);str=strcat('dis=',dis);text(3.3,0.315,str);%动画指令drawnow;holdoff;n=n+speed;%看stop是否按下data=get(gco,'UserData');method=data(1);%更新传递

17、参数set(stophld,'Userdata',btnNumbermnpdflabel);endotherwisewhile(method=1)%画f分布密度函数x=0:0.01:width;y=fpdf(x,m,n);plot(x,y,'EraseMode','normal');holdon%画近似正太分布密度函数y1=normpdf(x,n/(n-2),(2*nA2*(m+n-2)/m/(n-2)A2/(n-4)A0.5);plot(x,y1,'r');%图形参数调节axis(0width0lenth);set(gca,&#

18、39;XTick',0:xdis:width);set(gca,'YTick',0:ydis:lenth);gridon;legend('f分布','正态分布);%显示当前mtemp1=num2str(floor(m);str=strcat('m=',temp1);text(1.55,3.32,str);%显示当前ntemp2=num2str(floor(n);str=strcat('n=',temp2);text(1.78,3.32,str);%显示当前最大间距dis=num2str(max(abs(y-y1);

19、str=strcat('dis=',dis);text(1.55,3,str);%动画指令drawnow;holdoff;m=m+speed;%看stop是否按下data=get(gco,'UserData');method=data(1);%更新传递参数set(stophld,'Userdata',btnNumbermnpdflabel);endend%“Close”按钮执行程序elseifstrcmp(action,'stop')data=get(gco,'UserData');%读原有传递数据top=0.95

20、;left=0.80;btnWid=0.15;btnHt=0.08;%用acontinue”按钮替代"StopbtnNumber=1;labelStr='Continue'callbackStr='dandn(''continue'')'data(1)=btnNumber;%更新按钮标识btnPos=lefttop-btnHtbtnWidbtnHt;uicontrol(.'Style','pushbutton',.'Units','normalized',.

21、'Position',btnPos,.'String',labelStr,.'Callback',callbackStr,.'UserData',data);%acontinue”按钮执行程序elseifstrcmp(action,'continue')%读取传递数据data=get(gco,'UserData');method=data(1);m=data(2);n=data(3);%用"Stop”按钮替代"continue”btnNumber=2;labelStr='

22、Stop'callbackStr='dandn(''stop'')'top=0.95;left=0.80;btnWid=0.15;btnHt=0.08;btnPos=lefttop-btnHtbtnWidbtnHt;conthld=uicontrol(.'Style','pushbutton',.'Units','normalized',.'Position',btnPos,.'String',labelStr,.'Callback&#

23、39;,callbackStr,.'UserData',btnNumbermnpdflabel);%动画switchpdflabelcase1while(method=1)%画系x2分布密度函数a=n/2;b=2;%画x2分布密度函数x=xstart:0.1:xstart+width;y=gampdf(x,a,b);plot(x,y,'b','EraseMode','normal');holdon%画近似正太分布密度函数y1=normpdf(x,n,(2*n)A0.5);plot(x,y1,'r-');%图形参数调

24、节axis(xstartxstart+width0lenth);set(gca,'XTick',xstart:xdis:xstart+width);set(gca,'YTick',0:ydis:lenth);gridon;legend('X2分布','正态分布');%显示当前ntemp=num2str(floor(n);str=strcat('n=',temp);text(92,0.2,str);%显示当前最大间距dis=num2str(max(abs(y-y1);str=strcat('dis='

25、,dis);text(92,0.187,str);%动画指令drawnow;holdoffn=n+speed;%看stop是否按下data=get(gco,'UserData');method=data(1);%更新传递参数set(conthld,'UserData',btnNumbermnpdflabel);endcase2while(method=1)x=-width:0.1:width;y=tpdf(x,n);plot(x,y,'EraseMode','normal');holdon%画近似正太分布密度函数y1=normpd

26、f(x,0,(n/(n-2),0.5);plot(x,y1,'r-');%图形参数调节axis(-widthwidth0lenth);set(gca,'XTick',-width:xdis:width);set(gca,'YTick',0:ydis:lenth);gridon;legend('T分布','正态分布');%显示当前ntemp=num2str(floor(n);z=strcat('n=',temp);text(3.3,0.335,z);%显示当前最大间距dis=num2str(max(abs(y-y1);str=strcat('dis=',dis);text(3.3,0.315,str);%动画指令drawnow;h

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论