【发布时间】:2014-11-21 23:48:53
【问题描述】:
我正在研究一个联合 pdf 问题,其中随机变量
U = sqrt(X^2+Y^2)
X 和 Y 均匀分布在 (-2,2) 上。我想绘制X 和Y 的联合pdf。然后计算 U 的 pdf 并绘制它。我正在使用matlab R2011a,到目前为止,我已经想出了以下代码。在运行代码时,我收到一条错误消息
Undefined function or method 'makedist' for input arguement type 'char'.
我发现 makedist 不在 2011 版本上。所以我尝试使用
a=-2;
b=2;
X=a+(b-a)*rand(-10,10);
Y= a+(b-a)*rand(-10,10).
但是,我不确定如何计算 X 和 Y 的 pdf,然后从这里计算 XY 的联合 pdf。任何帮助,部分或整体的,都值得赞赏。
这是问题的matlab代码
%% Create distribution objects for X~U(-2,2) and Y~U(-2,2)
pdx=makedist('Uniform','lower',-2,'upper',2);
pdy=makedist('Uniform','lower',-2,'upper',2);
%Compute the pfs
x_ref=-10:1:10;
y_ref=-10:1:10;
pdf_x=pdf(pdx,x_ref);
pdf_y=pdf(pdy,y_ref);
% Plot the pdfs
figure 1;
stairs(x_ref,pdf_x,'g','Linewidth',2);
hold on;
stairs(y_ref,pdf_y,'r','Linewidth',2);
ylim([0 1.5]);
hold off;
% Joint pdf of x and Y
pdfXY=pdf_x*pdf_y;
figure 2;
plot(pdfXY);
%CDF and PDF of U
U=sqrt(X^2+Y^2);
Umin=0;
Umax=sqrt(b^2+b^2);
a=lower;
b=upper;
x=sqrt(U^2-Y^2);
xmin=0;
xmax=x;
ymin=0;
ymax=U;
Ucdf=integral2(pdfXY,xmin,xmax,ymin,ymax);
% plot CDF of U
figure 3;
plot(Ucdf)
我只是想绘制区域而不是任何特定的样本集。 X 和 Y 是连续独立均匀随机变量。
【问题讨论】:
-
您想要从一组样本值中获得的理论联合pdf还是经验联合pdf?
-
理论上,我认为 makedist 是可行的方法。
标签: matlab pdf random distribution