How do you make a random vector of only real values, using two other random vectors?
Show older comments
The title may be a bit confusing but I've attached the image of the problems i'm currently working on.

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
Bruno Luong
on 1 Dec 2018
The problem states x1 and x2 are uniform distribution, why you are using Gaussian distribution and get complex from negative numbers?
Kaleem Graham
on 1 Dec 2018
Bruno Luong
on 1 Dec 2018
No. Use RAND instead of RANDN
Kaleem Graham
on 1 Dec 2018
Answers (0)
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!