How do you make a random vector of only real values, using two other random vectors?

The title may be a bit confusing but I've attached the image of the problems i'm currently working on.
H.W.png
My Code
>> x1 = randn(L,1)*sigma + mu;
>> x2 = randn(L,1)*sigma + mu;
>> w1 = (sqrt(-2*log(x1))).*(cos(2*pi*x2));
>> w2 = (sqrt(-2*log(x1))).*(sin(2*pi*x2));
>> histogram(w1, 'normalization', 'pdf');
% Error using histogram
% Expected input number 1, x, to be real.
Is there anyway to only take the real portion of w1 and w2? Also am I going about the problem in the right way?

4 Comments

The problem states x1 and x2 are uniform distribution, why you are using Gaussian distribution and get complex from negative numbers?
I see what you're saying now, instead I should make x1 and x2 uniform distribution.
>> pd1 = makedist('Uniform');
>> x = 0:.01:1;
>> x1 = pdf(pd1,x);
Like this?
Thanks it worked! Was I on the right in regards to actually solving the problem? The mean of both w1 and w2 are about 0 and the std is about 1 for both of them.

Sign in to comment.

Answers (0)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Asked:

on 1 Dec 2018

Commented:

on 1 Dec 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!