Given two aid random variables X1 U0 1 and X2 U0 1 A new s
Solution
close all; clear all; clc;
N = 10^5; % number of samples
X1 = rand(1,N); % uniformly distributed random X1 variable between 0 and 1
X2 = rand(1,N); % uniformly distributed random X2 variable between 0 and 1
W1 = sqrt(-2.*log(X1)).*cos(2.*pi.*X2); % generated new variable
W2 = sqrt(-2.*log(X1)).*sin(2.*pi.*X2); % genrated new variable
Z = randn(1,N); % normal distributed random variable Z with mean 0 and variance 1
%% plotting of the PDF of W1
[Bin_height_W1, Bin_center_W1] = hist(W1,30);
pdf_W1 = Bin_height_W1./trapz(Bin_center_W1, Bin_height_W1); % generating
% pdf from histogram using trapezoidal integration
plot(Bin_center_W1, pdf_W1, \'-rs\', \'LineWidth\',1, \'MarkerSize\', 4); hold on
%% ploting of PDF of W2
[Bin_height_W2, Bin_center_W2] = hist(W2,30);
pdf_W2 = Bin_height_W2./trapz(Bin_center_W2, Bin_height_W2); % generating
% pdf from histogram using trapezoidal integration
plot(Bin_center_W2, pdf_W2, \'-ko\', \'LineWidth\', 1, \'MarkerSize\', 4);
%% plotting of PDF of plot Z
Bin_height_Z, Bin_center_Z] = hist(Z,30);
pdf_Z = Bin_height_Z./trapz(Bin_center_Z, Bin_height_Z);
plot(Bin_center_Z, pdf_Z, \'-mv\', \'LineWidth\', 1, \'MarkerSize\', 4);
xlabel(\'variables\', \'FontSize\', 15);
ylabel(\'pdf\', \'FontSize\', 15);
legend(\'pdf-W1\',\'pdf-W2\',\'pdf-normal distribution(0,1)\');
