dimanche 14 avril 2019

Use Matlab to get maximum value of the density function of inverse Gaussian distribution

New to Matlab and here is my question.

Question: Need to use the rejection method to find the maximum value of the density function of inverse Gaussian distribution as shown below.

enter image description here

% 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

Please feel free to let me know if u need any other information. Thank you!




Aucun commentaire:

Enregistrer un commentaire