《概率与统计分析.pptx》由会员分享,可在线阅读,更多相关《概率与统计分析.pptx(18页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、MATLAB 程序设计1MATLAB 程序设计程序设计道路与桥梁工程系道路与桥梁工程系 副主任副主任Department of Civil EngineeringHefei University of Technology 主讲人:王佐才主讲人:王佐才“黄山青年学者教授黄山青年学者教授”第三章 概率与统计分析2本章内容:统计分布的数字特征样本分布的频数直方图描述概率函数、分布函数、逆分布函数和随机数的发生第三章 概率与统计分析31.统计分布的数字特征平均值:平均值:mean Average or mean value of arraySyntaxM=mean(A)M=mean(A,dim)De
2、scriptionM=mean(A)returns the mean values of the elements along different dimensions of an array.If A is a vector,mean(A)returns the mean value of A.If A is a matrix,mean(A)treats the columns of A as vectors,returning a row vector of mean values.第三章 概率与统计分析41.统计分布的数字特征中值:中值:medianMedian value of arr
3、aySyntaxM=median(A)M=median(A,dim)DescriptionM=median(A)returns the median values of the elements along different dimensions of an array.A should be of type single or double.If A is a vector,median(A)returns the median value of A.If A is a matrix,median(A)treats the columns of A as vectors,returning
4、 a row vector of median values.第三章 概率与统计分析51.统计分布的数字特征几何平均值:几何平均值:geomeanGeometric meanSyntaxm=geomean(x)geomean(X,dim)Descriptionm=geomean(x)calculates the geometric mean of a sample.For vectors,geomean(x)is the geometric mean of the elements in x.For matrices,geomean(X)is a row vector containing t
5、he geometric means of each column.For N-dimensional arrays,geomean operates along the first nonsingleton dimension of X.第三章 概率与统计分析61.统计分布的数字特征调和平均值:调和平均值:harmmeanHarmonic meanSyntaxm=harmmean(X)harmmean(X,dim)Descriptionm=harmmean(X)calculates the harmonic mean of a sample.For vectors,harmmean(x)is
6、 the harmonic mean of the elements in x.For matrices,harmmean(X)is a row vector containing the harmonic means of each column.For N-dimensional arrays,harmmean operates along the first nonsingleton dimension of X.harmmean(X,dim)takes the harmonic mean along dimension dim of X.第三章 概率与统计分析71.统计分布的数字特征标
7、准差:标准差:stdStandard deviationSyntaxs=std(X)s=std(X,flag)s=std(X,flag,dim)s=std(X),where X is a vector,returns the standard deviation using(1)above.The result s is the square root of an unbiased estimator of the variance of the population from which X is drawn,as long as X consists of independent,iden
8、tically distributed samples.If X is a matrix,std(X)returns a row vector containing the standard deviation of the elements of each column of X.If X is a multidimensional array,std(X)is the standard deviation of the elements along the first nonsingleton dimension of X.第三章 概率与统计分析81.统计分布的数字特征方差:方差:varV
9、arianceSyntaxV=var(X)V=var(X,1)V=var(X,w)V=var(X,w,dim)DescriptionV=var(X)returns the variance of X for vectors.For matrices,var(X)is a row vector containing the variance of each column of X.For N-dimensional arrays,var operates along the first nonsingleton dimension of X.The result V is an unbiased
10、 estimator of the variance of the population from which X is drawn,as long as X consists of independent,identically distributed samples.第三章 概率与统计分析9例1.X 由下面的由下面的matlab命令流生成的矩阵:命令流生成的矩阵:X(:,1)=ones(10,1);X(1,1)=100;X(10,1)=0.01;rand(state,1);randn(state,1)X(:,2)=rand(10,1);X(:,3)=randn(10,1);X(:,3)=2
11、*abs(min(X(:,3)+X(:,3);求其平均值,中值,几何平均值,调和平均求其平均值,中值,几何平均值,调和平均值,标准差,方差。值,标准差,方差。X_mean=mean(X)X_mid=median(X)X_gmean=geomean(X)X_hmean=harmmean(X)X_std=std(X)X_var=var(X)第三章 概率与统计分析102.样本分布的频数直方图描述histHistogram plotSyntaxn=hist(Y)n=hist(Y,x)DescriptionA histogram shows the distribution of data values
12、.n=hist(Y)bins the elements in vector Y into 10 equally spaced containers and returns the number of elements in each container as a row vector.If Y is an m-by-p matrix,hist treats the columns of Y as vectors and returns a 10-by-p matrix n.Each column of n contains the results for the corresponding c
13、olumn of Y.No elements of Y can be complex or of type integer.n=hist(Y,x)where x is a vector,returns the distribution of Y among length(x)bins with centers specified by x.For example,if x is a 5-element vector,hist distributes the elements of Y into five bins centered on the x-axis at the elements i
14、n x,none of which can be complex.Note:use histc if it is more natural to specify bin edges instead of centers.第三章 概率与统计分析11例2.x 由下面的由下面的matlab命令流生成的矩阵:命令流生成的矩阵:randn(state,1)rand(state,31)x=randn(100,1);y=rand(100,1);subplot(2,2,1),hist(x,7)subplot(2,2,2),histfit(x,20)subplot(2,2,3),hist(y,7)subplot
15、(2,2,4),histfit(y,20)第三章 概率与统计分析12第三章 概率与统计分析133.概率函数、分布函数、逆分布函数和随机数的发生3.1 泊松分布(Poisson distribution)poisspdfPoisson probability density functionSyntaxY=poisspdf(X,lambda)DescriptionY=poisspdf(X,lambda)computes the Poisson pdf at each of the values in X using mean parameters in lambda.X and lambda c
16、an be vectors,matrices,or multidimensional arrays that all have the same size.A scalar input is expanded to a constant array with the same dimensions as the other input.The parameters in lambda must all be positive.第三章 概率与统计分析143.2 正态分布(Normal distribution)normpdfNormal probability density functionS
17、yntaxY=normpdf(X,mu,sigma)DescriptionY=normpdf(X,mu,sigma)computes the pdf at each of the values in X using the normal distribution with mean mu and standard deviation sigma.X,mu,and sigma can be vectors,matrices,or multidimensional arrays that all have the same size.A scalar input is expanded to a
18、constant array with the same dimensions as the other inputs.The parameters in sigma must be positive.第三章 概率与统计分析153.3 2 分布(Chi-square distribution)chi2pdfChi-square probability density functionSyntaxY=chi2pdf(X,V)DescriptionY=chi2pdf(X,V)computes the chi-square pdf at each of the values in X using t
19、he corresponding degrees of freedom in V.X and V can be vectors,matrices,or multidimensional arrays that have the same size,which is also the size of the output Y.A scalar input is expanded to a constant array with the same dimensions as the other input.第三章 概率与统计分析16例3.理解下面的MATLAB程序 mu=3;sigma=0.5;x
20、=mu+sigma*-3:-1,1:3;yf=normcdf(x,mu,sigma);P=yf(4)-yf(3),yf(5)-yf(2),yf(6)-yf(1);xd=1:0.1:5;yd=normpdf(xd,mu,sigma);%for k=1:3xxk=x(4-k):sigma/10:x(3+k);yyk=normpdf(xxk,mu,sigma);endsubplot(1,3,1),plot(xd,yd,b);hold onfill(x(3),xx1,x(4),0,yy1,0,g)text(mu-0.5*sigma,0.3,num2str(P(1),hold offsubplot(1,3,2),plot(xd,yd,b);hold onfill(x(2),xx2,x(5),0,yy2,0,g)text(mu-0.5*sigma,0.3,num2str(P(2),hold offsubplot(1,3,3),plot(xd,yd,b);hold onfill(x(1),xx3,x(6),0,yy3,0,g)text(mu-0.5*sigma,0.3,num2str(P(3),hold off第三章 概率与统计分析17Questions 18Thank you!