티스토리 뷰

clc;
clear;

%Random Generating Numbers
n=10000;

%12 Uniform Random Number Method
a=rand(n,12);
new_rand=zeros(n,1);

for i=1:12
    new_rand = new_rand+ a(:, i)
end
   
norm_rand = new_rand - 6;

subplot(1,3,1);
histfit(norm_rand);
xlabel('12-Method');

%Box-Muller Method
U1=rand(n,1);
U2=rand(n,1);

BXNORM=sqrt(-2*log(U1)).*cos(2*pi*U2);

subplot(1,3,2);
histfit(BXNORM);
xlabel('Box-Muller Method');

%Polar Rejection Method
v1=2*U1-1;
v2=2*U2-1;
S= v1.^2 + v2.^2;

PRNORM = v1.*sqrt((-2*log(S))./S);

subplot(1,3,3);
histfit(norm_rand);
xlabel('Polar Rejection Method');

'Language > Matlab R Python' 카테고리의 다른 글

matlab manual 7  (0) 2007.04.26