matlab二维相关随机变量样本点,MATLAB自学笔记(二十二):概率统计1

一、产生随机变量

1.二项分布的随机数据的产生(binornd)

R = binornd(N, P)

R = binornd(N, P, m, n,…)

R = binornd(N, P, [m, n,…])

其中,N,P是二项分布参数,返回服从参数为N,P的二项分布的随机数R;m指定随机数的个数,与R同维数;m,n分别表示R的行数和列数

Python

>> n = 10 : 10 : 60;

>> r = binornd(n,1./n,[1,6])

r =

0 1 1 0 1 1

>> r = binornd(n,.5,1,6)

r =

3 12 14 21 25 29

1

2

3

4

5

6

7

8

9

10

11

12

>>n=10:10:60;

>>r=binornd(n,1./n,[1,6])

r=

011011

>>r=binornd(n,.5,1,6)

r=

31214212529

2.正态分布的随机数据的产生(normrnd)

normrnd函数可以产生参数为μ、σ 的正态分布的随机数据

R = normrnd(mu, sigma)

R = normrnd(mu, sigma, m, n, …)

R = normrnd(mu, sigma, [m, n, …])

该函数返回均值为mu,标准差为sigma的正态分布随机数据;m指定随机数的个数,n表示R的列数

Python

>> n1 = normrnd(1:6, 1./(1:6))

n1 =

-0.2305 2.0480 2.2408 3.9705 5.2116 6.0727

>> n2 = normrnd(0,1,[1 5])

n2 =

1.4115 -0.0146 -0.5378 -1.8348 2.6355

>> n3 = normrnd(0,1,[5 5])

n3 =

0.2908 -2.5245 0.4566 0.3342 0.0467

1.0656 -1.0063 -0.5062 0.3460 -1.0647

0.5352 -0.4242 -1.1846 -0.1195 0.0399

-0.3873 -0.6612 0.7818 0.7162 0.9169

-0.3196 0.7276 -0.0804 0.2279 -0.4088

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

>>n1=normrnd(1:6,1./(1:6))

n1=

-0.23052.04802.24083.97055.21166.0727

>>n2=normrnd(0,1,[15])

n2=

1.4115-0.0146-0.5378-1.83482.6355

>>n3=normrnd(0,1,[55])

n3=

0.2908-2.52450.45660.33420.0467

1.0656-1.0063-0.50620.3460-1.0647

0.5352-0.4242-1.1846-0.11950.0399

-0.3873-0.66120.78180.71620.9169

-0.31960.7276-0.08040.2279-0.4088

二、概率密度计算

1.通用函数概率密度值(pdf、ksdensity)

pdf函数可以轻松计算概率密度

y = pdf(name, X, A)

y = pdf(name, X, A, B)

y = pdf(name, X, A, B, C)

y = pdf(obj, X)

其中,返回在x = X处,参数为A、B、C的概率密度值,对于不同的分布,参数的个数不同

name为分布函数名,其值可以在MATLAB中按如下方式获取:

在命令行窗口中输入

Python

>> help pdf

1

>>helppdf

Python

pdf Density function for a specified distribution.

Y = pdf(NAME,X,A) returns an array of values of the probability density

function for the one-parameter probability distribution specified by NAME

with parameter values A, evaluated at the values in X.

Y = pdf(NAME,X,A,B) or Y = pdf(NAME,X,A,B,C) returns values of the

probability density function for a two- or three-parameter probability

distribution with parameter values A, B (and C).

The size of Y is the common size of the input arguments. A scalar input

functions as a constant matrix of the same size as the other inputs. Each

element of Y contains the probability density evaluated at the

corresponding elements of the inputs.

NAME can be:

'beta' or 'Beta',

'bino' or 'Binomial',

'burr' or 'Burr',

'chi2' or 'Chisquare',

'exp' or 'Exponential',

'ev' or 'Extreme Value',

'f' or 'F',

'gam' or 'Gamma',

'gev' or 'Generalized Extreme Value',

'gp' or 'Generalized Pareto',

'geo' or 'Geometric',

'hn' or 'Half Normal',

'hyge' or 'Hypergeometric',

'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',

'stable'or 'Stable',

't' or 'T',

'unif' or 'Uniform',

'unid' or 'Discrete Uniform',

'wbl' or 'Weibull'.

pdf is a generic function that accepts a distribution by name. It is

faster to use a more specialized function when possible, such as

NORMPDF for the normal distribution.

See also cdf, icdf, mle, random.

pdf 的参考页

名为 pdf 的其他函数

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

pdfDensityfunctionforaspecifieddistribution.

Y=pdf(NAME,X,A)returnsanarrayofvaluesoftheprobabilitydensity

functionfortheone-parameterprobabilitydistributionspecifiedbyNAME

withparametervaluesA,evaluatedatthevaluesinX.

Y=pdf(NAME,X,A,B)orY=pdf(NAME,X,A,B,C)returnsvaluesofthe

probabilitydensityfunctionforatwo-orthree-parameterprobability

distributionwithparametervaluesA,B(andC).

ThesizeofYisthecommonsizeoftheinputarguments.Ascalarinput

functionsasaconstantmatrixofthesamesizeastheotherinputs.Each

elementofYcontainstheprobabilitydensityevaluatedatthe

correspondingelementsoftheinputs.

NAMEcanbe:

'beta'or'Beta',

'bino'or'Binomial',

'burr'or'Burr',

'chi2'or'Chisquare',

'exp'or'Exponential',

'ev'or'Extreme Value',

'f'or'F',

'gam'or'Gamma',

'gev'or'Generalized Extreme Value',

'gp'or'Generalized Pareto',

'geo'or'Geometric',

'hn'or'Half Normal',

'hyge'or'Hypergeometric',

'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',

'stable'or'Stable',

't'or'T',

'unif'or'Uniform',

'unid'or'Discrete Uniform',

'wbl'or'Weibull'.

pdfisagenericfunctionthatacceptsadistributionbyname.Itis

fastertouseamorespecializedfunctionwhenpossible,suchas

NORMPDFforthenormaldistribution.

Seealsocdf,icdf,mle,random.

pdf的参考页

名为pdf的其他函数

注:没错,就是pdf

ksdensity函数可以求取一般函数/数据的概率密度

[f, xi] = ksdensity(x)

f = ksdensity(x, xi)

ksdensity(…)

ksdensity(ax, …)

[f, xi, u] = ksdensity(…)

[…] = ksdensity(… , ‘name’, value)

其中,x 为带统计的向量;xi 为计算概率密度的点;f为得到的概率密度;ax 指定绘制位置坐标轴对象;name和value 为可选属性及属性值

Python

>> p1 = pdf('Normal',-2:2,0,1)

p1 =

0.0540 0.2420 0.3989 0.2420 0.0540

1

2

3

4

5

>>p1=pdf('Normal',-2:2,0,1)

p1=

0.05400.24200.39890.24200.0540

2.专用函数概率密度值(’name’+pdf)

Y = binopdf(X, N, P):X为计算点;N为试验总次数;P为每次试验中事件发生的概率;Y为概率密度

其命名规则为‘name’+pdf。name 与上面的相同,即可调用相应的专用函数求概率密度值

三、累计概率分布

1.通用函数累计概率值(cdf)

cdf函数可以用来计算随机变量x≤X的概率之和(即累计概率值)

Y = cdf(‘name’, X, A)

Y = cdf(‘name’, X, A, B)

Y = cdf(‘name’, X, A, B, C)

Y = cdf(obj, X)

其中,返回在x = X处,参数为A、B、C的概率密度值,对于不同的分布,参数的个数不同

name为分布函数名,与pdf中name相同;obj为高斯联合分布对象

2.专用函数累计概率值(’name’+cdf)

其命名规则为‘name’+cdf。name 与上面的相同,即可调用相应的专用函数求累计概率值

赞赏作者

喜欢 (1)or分享 (0)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值