简体   繁体   中英

How to plot pdf of uniform random variables in Matlab

x and y have the uniform distribution and I want to plot pdf of z in Matlab.

x ~ U(0,1)

y ~ U(0,1)

Z = (-2.ln(x))^0.5  * cos(2.pi.y)

How can I do this?

It would take some time to derive the distribution for Z though it is probably easiest to start with the CDF such as P(Z<=z) then condition on X=x or Y=y. Not clear which will be easiest path to eventually get the explicit CDF or PDF. But P(Z<=z|X = x) or P(Z<=z|Y = y) seems best approach. Cross Validated ( https://stats.stackexchange.com/ ) is probably the best place to get the analytical derivation in progress here .

Empirically this is easy to obtain and with a large enough sample size, it should work very well for many applications.

N = 5000;
X = rand(N,1);
Y = rand(N,1);
Z = cos(2*pi*Y).*(-2*log(X)).^2;

figure, hold on, box on
histogram(Z,'Normalization','pdf')

Z 的直方图

If you wanted to see Z as a function of (X,Y) , these might help.

n = 100;
x = linspace(0,1,n);
y = linspace(0,1,n);
[X,Y] = meshgrid(x,y);
Z = cos(2*pi*Y).*(-2*log(X)).^2;

The contour plot isn't very usefulZ 的等值线图

But the surface plot shows a bit more what is going on based on (X,Y) Z 的曲面图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM