Reputation:
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
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')
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
But the surface plot shows a bit more what is going on based on (X,Y)
Upvotes: 2