matlab finitepmf,Probability and Stochastic Processes_Roy D.Yates_Matlab Source Code

finitecov covxy=finitecov(SX,SY,PXY)

function covxy=finitecov(SX,SY,PXY); %Usage:cxy=finitecov(SX,SY,PXY)

%returns the covariance of

%finite random variables X and Y

%given by grids SX,SY,and PXY

ex=finiteexp(SX,PXY);

ey=finiteexp(SY,PXY);

R=finiteexp(SX.*SY,PXY);

covxy=R-ex*ey;Input:Grids SX,SY and probability grid PXY describing the?nite random

variables X and Y.

Output:covxy,the covariance of X and Y.

finiteexp ex=finiteexp(sx,px)

function ex=finiteexp(sx,px);

%Usage:ex=finiteexp(sx,px)

%returns the expected value E[X]

%of finite random variable X described %by samples sx and probabilities px

ex=sum((sx(:)).*(px(:)));Input:Probability vector px,vector of samples sx describing random

variable X.

Output:ex,the expected value E[X].

finitepmf y=finitepmf(sx,p,x)

function pmf=finitepmf(sx,px,x)

%finite random variable X:

%vector sx of sample space

%elements{sx(1),sx(2),...}

%vector px of probabilities

%px(i)=P[X=sx(i)]

%Output is the vector

%pmf:pmf(i)=P[X=x(i)]

pmf=zeros(size(x(:)));

for i=1:length(x)

pmf(i)=sum(px(find(sx==x(i)))); end Input:sx is the range of a?nite random variable X,px is the corresponding

probability assignment,x is a vector

of possible sample values Output:y is a vector with y(i)= P[X=x(i)].

finiterv x=finiterv(sx,p,m)

function x=finiterv(s,p,m) %returns m samples

%of finite(s,p)rv

%s=s(:);p=p(:);

r=rand(m,1);

cdf=cumsum(p);

x=s(1+count(cdf,r));Input:sx is the range of a?nite random variable X,p is the corresponding probability assignment,m is

positive integer

Output:x is a vector of m sample values y(i)=

F X(x(i)).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值