⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jf_box_muller_transform.m

📁 Box-Muller变换
💻 M
字号:
% Filename:    jf_Box_Muller_transform.m
% Modified:    09/14/2007, by JFang
% Description: Box-Muller transform,将[0,1]均匀分布转换为[0,1]高斯正态分布
close all;
clf;
clear;

%--------------- Box-Muller Transformation begin---------------
% A transformation which transforms from a two-dimensional continuous 
% uniform distribution to a two-dimensional bivariate normal distribution.  
if 1
n_steps = 100000;
gauss_xs = zeros(1, n_steps);
gauss_xn = zeros(1, n_steps);

uniform_u1 = rand(1, n_steps);
uniform_u2 = rand(1, n_steps);

for ctr_i = 1:1:n_steps
  tmp = sqrt(-2*log(uniform_u1(ctr_i)));
  gauss_xs(ctr_i) = tmp*cos(2*pi*uniform_u2(ctr_i));

  tmp = sqrt(-2*log(uniform_u2(ctr_i)));
  gauss_xn(ctr_i) = tmp*sin(2*pi*uniform_u1(ctr_i));
end

mean(gauss_xs)
var(gauss_xs)
mean(gauss_xn)
var(gauss_xn)
end
%--------------- Box-Muller Transformation end--------------- 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -