《常见分布图形MATLAB编程》由会员分享,可在线阅读,更多相关《常见分布图形MATLAB编程(12页珍藏版)》请在金锄头文库上搜索。
1、文档供参考,可复制、编制,期待您的好评与关注! % 标准正态分布的密度计算 y=normpdf(0, 0,1)y =0.3989% 标准正态分布的概率计算 pro=normcdf(3, 0,1)-normcdf(-3, 0,1)pro =0.9973% 标准正态分布的分位数计算quantile=norminv(0.95,0,1)quantile =1.6449 quantile=norminv(0.025,0.975,0,1)quantile = -1.9600 1.9600 quantile=binoinv(0.025,0.975,100,0.1)quantile = 5 16% 标准正态分
2、布的密度曲线图x=-3:0.1:3;y=1/sqrt(2*pi)*exp(-x.2/2);plot(x, y)或 ezplot(1/sqrt(2*pi)*exp(-x2/2),-3,3)%标准正态随机数的直方图x=random(norm,0,1,1,1000);hist(x)% 大数定律的验证:独立同分布于U0,1的随机变量的均值与方差的近似n=100000; x=; err=; err1=;for i=1000:1000:n u=random(Uniform,0,1,1,1000); x=x,u; ave=sum(x)/length(x);err=err,abs(ave-0.5)/0.5;
3、%相对误差dev=sum(x-ave).2)/(length(x)-1);err1=err1,abs(dev-1/12)*12; %相对误差endi=1000:1000:n;plot(i, err, r*, i, err1, b)% 中心极限定理的验证:独立同分布于U0,1的随机变量的和的分布n=100000;u1=random(Uniform,0,1,1,n); hist(u1) u2=random(Uniform,0,1,1,n); hist(u1+u2)u3=random(Uniform,0,1,1,n); hist(u1+u2+u3)u4=random(Uniform,0,1,1,n)
4、; hist(u1+u2+u3+u4)u5=random(Uniform,0,1,1,n); hist(u1+u2+u3+u4+u5)u6=random(Uniform,0,1,1,n); hist(u1+u2+u3+u4+u5+u6)% 中心极限定理的验证:独立同分布于B(10,0.1)的随机变量的和的分布n=100000;u1=random(Binomial,10,0.1,1,n);hist(u1)u2=random(Binomial,10,0.1,1,n);hist(u1+u2)u3=random(Binomial,10,0.1,1,n);hist(u1+u2+u3)u4=random(
5、Binomial,10,0.1,1,n);hist(u1+u2+u3+u4)u5=random(Binomial,10,0.1,1,n);hist(u1+u2+u3+u4+u5)u6=random(Binomial,10,0.1,1,n);hist(u1+u2+u3+u4+u5+u6)u7=random(Binomial,10,0.1,1,n);hist(u1+u2+u3+u4+u5+u6+u7)u8=random(Binomial,10,0.1,1,n);hist(u1+u2+u3+u4+u5+u6+u7+u8)u9=random(Binomial,10,0.1,1,n);hist(u1+u
6、2+u3+u4+u5+u6+u7+u8+u9)% 中心极限定理的验证:独立同分布于U0,1的随机变量的均值的分布ave1=; ave2=;for i=1:600 %取600个样本ave1=ave1,sum(random(Uniform,0,1,1,10)/10; %样本容量为10ave2=ave2,sum(random(Uniform,0,1,1,50)/50; %样本容量为50end hist(ave1)clf;hist(ave2)%关于常用随机数的使用介绍 help random RANDOM Generates random numbers from a named distributi
7、on. The appropriate syntax depends on the number of parameters in the distribution you are using: R = RANDOM(NAME,A,M,N) returns an M-by-N array of random numbers from the named distribution with parameter A. R = RANDOM(NAME,A,B,M,N) returns an M-by-N array of random numbers from the named distribut
8、ion with parameters A, and B. R = RANDOM(NAME,A,B,C,M,N) returns an M-by-N array of random numbers from the named distribution with parameters A, B, and C. The name can be: beta or Beta, bino or Binomial, chi2 or Chisquare, exp or Exponential, f or F, gam or Gamma, geo or Geometric, hyge or Hypergeo
9、metric, logn or Lognormal, nbin or Negative Binomial, ncf or Noncentral F, nct or Noncentral t, ncx2 or Noncentral Chi-square, norm or Normal, poiss or Poisson, rayl or Rayleigh, t or T, unif or Uniform, unid or Discrete Uniform, weib or Weibull. Both M and N are integers. Alternatively you can omit N and specify M as a vector of two integers. If you omit both M and N, then R is a 1-by-1 array. /