user6250685
user6250685

Reputation:

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?

Upvotes: 0

Views: 1034

Answers (1)

SecretAgentMan
SecretAgentMan

Reputation: 2854

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

Histogram of 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 useful Contour Plot of Z

But the surface plot shows a bit more what is going on based on (X,Y) Surface Plot of Z

Upvotes: 2

Related Questions