Matlab的新手,这是我的问题。
问题:需要使用拒绝方法来找到反高斯分布的密度函数的最大值,如下所示。
% Using Rejection Method to generate standard normal N(0,1).
% Check how many realizations have been rejected
rng(123);
N = 100000;
Count = 0;
Rejection = 0;
X = [];
tic %Timer
while Count<= N
U1 = -4+(4-(-4))*rand; % U1: Uniform(-4, 4)
U2 = 0.5*rand; % U2: Uniform(0, 0.5)
if U2<= 1/(sqrt(2*pi))*exp(-U1^2/2)
Count = Count + 1;
X = [X,U1];
else
Rejection = Rejection + 1;
end
如果您需要其他任何信息,请随时告诉我。谢谢!