Gaussian and binary probability random variables numerical reconstruction

288 Views Asked by At

in my probability class I was given this question dealing with MATLAB code the purpose of which is to create and re estimate the random variables Z1, Z2, which reads as follows:

rng('default')

exps = 1e5;

sigX = 6;

sigY = 1;

% generate some normal (Gaussian) variables

X = sigX*randn(exps,1);

Y = sigY*randn(exps,1);

% generate a binary variable

B = rand(exps,1)>0.5;

% generate Z1 and Z2

Z1 = B.*X+(1-B).*Y;

Z2 = 0.5*(X + Y);

% display histograms (1st order distribution estimate)

subplot(211);

hist(Z1,1000)

xlabel('bins')

ylabel('frequency')

axis tight

subplot(212);

hist(Z2,1000)

xlabel('bins')

ylabel('frequency')

axis tight

And the output graphs are the following:

enter image description here

The question asks us to explain the results of these graphs (what is expected or not and so forth). We are also asked to relate this question to a previous result obtained which I already solved:

If two independent random variables X and Y which are independent from A which discretely receives one of two values {1,2} equally, defining the following random variable:

enter image description here

then we know the following information

enter image description here

And that the addition of two independent Gaussian variables is again Gaussian with sum of means and variances.

I have no idea how the MATLAB code works and how to relate the previous problem that I solved and how to explain the results so this is my problem, in explaining the results and relating the previous question. I thank all helpers out there