代码
%% clear
clc;
clear;
%% uniform distribution
N = 1000000;
U1 = rand(1, N);
U2 = rand(1, N);
%% Get Gussion distribution using box-Muller transfrom
Z1 = sqrt(-2 * log(U1)) .* cos(2 * pi * U2);
Z2 = sqrt(-2 * log(U1)) .* sin(2 * pi * U2);
%% visualisztion of PDF
subplot(2, 2, 1), hist(U1, 100), title( ‘The PDF of U1‘ );
subplot(2, 2, 2), hist(U2, 100), title( ‘The PDF of U2‘ );
subplot(2, 2, 3), hist(Z1, 100), title( ‘The PDF of Z1‘ );
subplot(2, 2, 4), hist(Z2, 100), title( ‘The PDF of Z2‘ );